Reputation: 3
when I use curl to get the content of an html page, I got a wired content which look like a script. Can you tell me what's wrong with my code, and what is this wired content ?
There is my controller :
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://twitter.com',
));
$data = curl_exec($curl);
dd($data);
curl_close($curl);
And there is what it's look like in the console.
Thank you for all of your answers.
Upvotes: 0
Views: 579
Reputation: 1233
Do not use dd()
to print the $data
variable,
Use print_r
or var_dump
to see the exact response returned by curl.
Its the dd
that adds extra JS to the output
Here is a better code to do this :
$url="https://twitter.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
print_r($result);
Upvotes: 1
Reputation: 3
Well, thanks for your help, now it works !
At the first try it didn't, but then I just deleted those two lines :
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
and $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
and know everything is okay.
Upvotes: 0