I'm thinking that you need to remove the:
   $contents = fread($filename, 1000000);
line. This is probably making the file pointer point to the end of the file.

-----Original Message-----
From: Jason Soza [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 4:17 PM
To: David Robley; [EMAIL PROTECTED]
Subject: RE: [PHP] Re: Using fopen()/fread()/fscanf()

I'm fairly certain that fopen() is working fine - I can echo "$contents";
and it works great, but it displays the entire page that I fetched. I just
want certain parts of the page and unfortunately, fscanf() doesn't seem to
think $contents or $filename are valid. Just more info on this, I tried
replacing fscanf($filename,...) with fscanf($contents,...) and got the same

Jason Soza

-----Original Message-----
From: David Robley [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 22, 2002 8:37 PM
Subject: [PHP] Re: Using fopen()/fread()/fscanf()

> I think I'm pretty close to getting this right (maybe!), I've been reading
> through the manual, but can't seem to work it out. I keep getting this
> error:
> [Mon Jul 22 19:03:24 2002] [error] PHP Warning:  Supplied argument is not
> valid File-Handle resource in index.php on line 66
> I'm trying to open a URL, read the contents, then pull out specific info
> found between specific HTML tags. This is what I have so far:
> 63| <?php
> 64|   $filename =
> fopen("http://www.kinyradio.com/juneaunews/latest_juneau_news.html";, "r");
> 65|   $contents = fread($filename, 1000000);
> 66|   while($headlines = fscanf($filename, "<p style=\"padding-left:
> 45\"><font face=\"Verdana\" size=\"3\"><b>%[a-zA-Z0-9,. ]</b></font>",
> $headline)) {
> 67|                   extract($headlines);
> 68|                   print "<a
> ne</a><br>";
> 69|                   }
> 70|   fclose($filename);
> 71| ?>
> Any ideas? Any other functions I could try instead of fscanf()?

That error indicates that fopen failed to open the requested file. Given
that the URL works fine in a browser, is it possible that your php is not
configured to do remote fopen? Check the setting of allow_url_fopen in

It is a good idea to test the result of such calls before trying to use
the result:

fopen('Whatever') or exit('Couldn't get it, Boss!');


if(fopen('whatever') {
  do good things;
  bleat vigorously;

David Robley
Temporary Kiwi!

Quod subigo farinam

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to