0

Hello,

I made a script that fetches the HTML of a remote page, on another server:

// $URL[$i] has the value of a url, ex. http://www.google.com
$lines = file($URL[$i]);

$the_file='';
if($lines)
foreach ($lines as $line)
{
	$the_file .= $line . "<br />\n";
}

//if I echo the variable $the_file, I get the complete html of the url provided

The above code works fine, but i had to change it to curl functions, and everything got messed up.. for some pages it works, for most of the other pages it doesn't, I get half of html or some strange lines of html, not what I am supposed to get.


This is the code that doesn't work:

$contents = '';
$curl_ses = curl_init();
curl_setopt($curl_ses, CURLOPT_URL,$URL[$i]);
curl_setopt($curl_ses, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec ($curl_ses);
curl_close ($curl_ses);

$the_file = $contents;

For example, if the URL was http://www.yahoomail.com, and I try to echo the variable $the_file php echos nothing.. and for some sites it echos some html.

Could you please tell me what I've done wrong?

Thanks

1
Contributor
1
Reply
3
Views
7 Years
Discussion Span
Last Post by theighost
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.