RE: [PHP] Re: Using fopen()/fread()/fscanf()
| From: | Martin Towell | Date: | Tue, 23 Jul 2002 06:16:06 +0000 |
| Subject: | RE: [PHP] Re: Using fopen()/fread()/fscanf() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-109044@lists.php.net to get a copy of this message | ||
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:solja@gci.net]
Sent: Tuesday, July 23, 2002 4:17 PM
To: David Robley; php-general@lists.php.net
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
result.
Thanks,
Jason Soza
-----Original Message-----
From: David Robley [mailto:robleyd@paradise.net.nz]
Sent: Monday, July 22, 2002 8:37 PM
To: php-general@lists.php.net
Subject: [PHP] Re: Using fopen()/fread()/fscanf()
In article <JNEPLIKJKFFIIBCBFMJFEEGGCCAA.solja@gci.net>, solja@gci.net
says...
> 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
a
> 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
>
href=\"http://www.kinyradio.com/juneaunews/latest_juneau_news.html\">$headli
> 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
phpinfo()
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!');
or
if(fopen('whatever') {
do good things;
}else{
bleat vigorously;
}
Cheers
--
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