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]);

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?


Can someone help please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.