BRUm Posted August 26, 2006 Share Posted August 26, 2006 Hi,I need to file_get_contents of multiple website dynamically, so I use arrays in a loop to connect to. Here's a snippet:[code=php:0] for ($i = 1; $i < sizeof($linkarray[0])-3; $i++){ echo ("<a href=" . $linkarray[1][$i] . "> <font color='red'><b>" . $linkarray[2][$i] . "</b></a></font><br><br> "); $ccontent = file_get_contents($linkarray[1][$i]); $rele = preg_match("/".$pieces[0].".*/", $ccontent, $rel); ECHO $rel[0]."<BR><BR>"; } [/code]So it loops, and gets the contents of some sites, yet when I echo the output array $rel[0]; I get Failed to stream for each one, despite them being valid URLs.If someone could help it would be great ,Thanks,Lee. Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/ Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 How is your array structured?[code]echo '<pre>', print_r($linkarray, true), '</pre>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80654 Share on other sites More sharing options...
BRUm Posted August 26, 2006 Author Share Posted August 26, 2006 It's not a complicated array, just the basic: [/code][1] => Array ( [0] => "http://froogle.google.co.uk/froogle?=en&q=cars&btnG=Google+Search&sa=N&tab=wf" [1] => "/movies/reviews?cid=b3d997eccb5717fb&fq=cars&sa=X&oi=showtimes&ct=reviews&cd=2" [2] => "http://www.channel4.com/4car/" [3] => "http://www.cars.com/" [4] => "http://www.autotrader.co.uk/" [5] => "http://uk.cars.yahoo.com/" [6] => "http://www.imdb.com/title/tt0317219/" [7] => "http://www.carsthemovie.com/")[/code]This is only the $linkarray[1][$i] part. $linkarray[0] and [2] contain other stuff. Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80656 Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 First couple of elements look as though they should be all 1 element[code]<?php$linkarray = array ( 1 => array( "http://froogle.google.co.uk/froogle?=en&q=cars&btnG=Google+Search&sa=N&tab=wf/movies/reviews?cid=b3d997eccb5717fb&fq=cars&sa=X&oi=showtimes&ct=reviews&cd=2", "http://www.channel4.com/4car/", "http://www.cars.com/", "http://www.autotrader.co.uk/", "http://uk.cars.yahoo.com/", "http://www.imdb.com/title/tt0317219/", "http://www.carsthemovie.com/", ));$ccontent = file_get_contents($linkarray[1][0]);echo $ccontent;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80659 Share on other sites More sharing options...
BRUm Posted August 26, 2006 Author Share Posted August 26, 2006 But if they're all one element, then how do I distinguish between each one? I need to use each individual URL and it's dynamic too.Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80660 Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 There are seven elements in the array I posted - there were 8 in yours. I combined the first 2. Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80665 Share on other sites More sharing options...
BRUm Posted August 26, 2006 Author Share Posted August 26, 2006 Ah right, yes I understand. Still, I get:[code]Warning: file_get_contents("http://www.carsthemovie.com/"): failed to open stream: No such file or directory in /home/hydropow/public_html/izearch/searched.php on line 161[/code] Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80668 Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 Check this setting in php.ini fileallow_url_fopen = On Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80672 Share on other sites More sharing options...
BRUm Posted August 26, 2006 Author Share Posted August 26, 2006 It is allowed because when I manually use:[code=php:0]$test = Get_File_Contents("http://www.example.com");echo $test;[/code]That streams and returns fine.. :/ Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80676 Share on other sites More sharing options...
BRUm Posted August 26, 2006 Author Share Posted August 26, 2006 Anyone know? :/ Quote Link to comment https://forums.phpfreaks.com/topic/18705-help-file_get_contents/#findComment-80758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.