whitepaint Posted July 10, 2008 Share Posted July 10, 2008 Greetings, I am using file_get_contents() to obtain data for an indexing project I am doing. The data I am using is from Wikipedia. With some URLs, there is no issue, with others, the function returns nothing. The first example below works; The second example does not. http://en.wikipedia.org/wiki/USS_Enterprise_%28CVN-65%29 http://en.wikipedia.org/wiki/SMS_Gro%C3%9Fer_Kurf%C3%BCrst_%281913%29 When I call the function, I print the data immediately. Any ideas out there with what is going on? Any help is appreciated. Cheers Link to comment https://forums.phpfreaks.com/topic/114143-file_get_contents-works-sometimes/ Share on other sites More sharing options...
aim25 Posted July 10, 2008 Share Posted July 10, 2008 Post some code. Link to comment https://forums.phpfreaks.com/topic/114143-file_get_contents-works-sometimes/#findComment-586700 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2008 Share Posted July 10, 2008 I'm not sure why, but using file_get_contents on the second url failed in my tests. Using cURL worked: <?php $urls = array('http://en.wikipedia.org/wiki/USS_Enterprise_%28CVN-65%29', 'http://en.wikipedia.org/wiki/SMS_Gro%C3%9Fer_Kurf%C3%BCrst_%281913%29'); foreach ($urls as $url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); echo $output; }?> Ken Link to comment https://forums.phpfreaks.com/topic/114143-file_get_contents-works-sometimes/#findComment-586719 Share on other sites More sharing options...
whitepaint Posted July 10, 2008 Author Share Posted July 10, 2008 my code is as simple as $content = file_get_contents($_POST['links']); print $content; Post some code. Link to comment https://forums.phpfreaks.com/topic/114143-file_get_contents-works-sometimes/#findComment-587008 Share on other sites More sharing options...
whitepaint Posted July 10, 2008 Author Share Posted July 10, 2008 Thanks fot the help, I am using your code now. I'm not sure why, but using file_get_contents on the second url failed in my tests. Using cURL worked: <?php $urls = array('http://en.wikipedia.org/wiki/USS_Enterprise_%28CVN-65%29', 'http://en.wikipedia.org/wiki/SMS_Gro%C3%9Fer_Kurf%C3%BCrst_%281913%29'); foreach ($urls as $url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); echo $output; }?> Ken Link to comment https://forums.phpfreaks.com/topic/114143-file_get_contents-works-sometimes/#findComment-587016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.