Jump to content


Photo

[HELP] File_Get_Contents


  • Please log in to reply
9 replies to this topic

#1 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 09:08 AM

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:

      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>";
 
      } 


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.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 August 2006 - 10:07 AM

How is your array structured?

echo '<pre>', print_r($linkarray, true), '</pre>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 10:35 AM

It's not a complicated array, just the basic:

[/code]
[1] => Array
        (
            [0] => "http://froogle.googl...ch&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/...tle/tt0317219/"
            [7] => "http://www.carsthemovie.com/"
)
[/code]

This is only the $linkarray[1][$i] part. $linkarray[0] and [2] contain other stuff.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 August 2006 - 10:53 AM

First couple of elements look as though they should be all 1 element
<?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;
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 10:56 AM

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.

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 August 2006 - 11:05 AM

There are seven elements in the array I posted - there were 8 in yours. I combined the first 2.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 11:16 AM

Ah right, yes I understand. Still, I get:

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


#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 August 2006 - 11:27 AM

Check this setting in php.ini file

allow_url_fopen = On
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 11:45 AM

It is allowed because when I manually use:

$test = Get_File_Contents("http://www.example.com");
echo $test;

That streams and returns fine.. :/

#10 BRUm

BRUm
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 August 2006 - 03:17 PM

Anyone know? :/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users