I'm trying to grab a web page from a site using file_get_contents. When i pass a single url into file_get_contents(http://www.example.co.uk) it works fine. How ever i am using a while loop and passing in a url from a list in a text file. When i use this loop i get
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /drive2/fpgshttpd/definedwebdesign/get3.php on line 9
Warning: file_get_contents(http://www.google.com ): failed to open stream: No such file or directory in /drive2/fpgshttpd/definedwebdesign/get3.php on line 9
but the last url in the list will work and can be echo'd.
Please help its driving me mad i have tryed using fopen and fget instead of file_get_contents but i get the same error. The url has been passed to file_get_contents() correctly as it names the url in the error warning.
here's the code:
<?php
$url='';
$filename = "list.txt";
$fp = fopen( $filename, "r" ) or die("Can't open File");
while ( ! feof( $fp ) ) {
$url = fgets($fp);
$file = file_get_contents($url, "r");
echo $file;
}
?>
Thanks
Tim.