RE: [PHP] Re: Using fopen()/fread()/fscanf()
Okay, I removed that line and I no longer get the invalid File-Handle resource error, but I also don't get anything useful. Maybe my fscanf() line needs some work? With this new code, if I print_r($headlines); I get 229 of these: Array ( [0] = ) Code: $filename = fopen(http://www.kinyradio.com/juneaunews/latest_juneau_news.html;, r); while($headlines = fscanf($filename, p style=\padding-left: 45\font face=\Verdana\ size=\3\b%[a-zA-Z0-9,. ]/b/font)) { print_r($headlines); } fclose($filename); What the fscanf() code -should- be doing, or at least what I intend for it to do, is grab everything between p style=padding-left: 45...b and /b/font - is my code structured for that? -Original Message- From: Martin Towell [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 10:16 PM To: 'Jason Soza'; David Robley; [EMAIL PROTECTED] Subject: RE: [PHP] Re: Using fopen()/fread()/fscanf() I'm thinking that you need to remove the: $contents = fread($filename, 100); 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 result. Thanks, Jason Soza -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Using fopen()/fread()/fscanf()
On Tuesday 23 July 2002 14:16, Jason Soza wrote: 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. Not sure why you're using fscanf() and why it doesn't work. I would use preg_match() on $contents. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Communications satellite used by the military for star wars. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Using fopen()/fread()/fscanf()
Alright, I see that this is probably the way to go, but I'm dying here. I have this: $filename = fopen(http://www.kinyradio.com/juneaunews/latest_juneau_news.html;, r); $contents = fread($filename, 100); preg_match_all(|font face=\Verdana\ size=\3\b+[-a-zA-Z0-9,. ]+|i, $contents, $out); print_r($out); And it returns this: Array ( [0] = Array ( [0] = Injured hiker [1] = Toy guns looked real enough [2] = U-S Forest Service Chief visiting [3] = Millions in compensation divided up [4] = Alaska Air [5] = One car [6] = Services [7] = Talkeetna ) [1] = Array ( [0] = Injured hiker [1] = Toy guns looked real enough [2] = U-S Forest Service Chief visiting [3] = Millions in compensation divided up [4] = Alaska Air [5] = One car [6] = Services [7] = Talkeetna ) ) This is definitely progress, but the headlines are truncated. I have a feeling this has something to do with linebreaks, but I don't know how to account for those. For example, $out[0][0] should read Injured hiker rescued on Mt. Juneau and $out[0][2] should end with ...Alaska for the first time. The manual entries for preg_match and preg_match_all pretty much assume you have a working knowledge of reg expressions, which I don't, and a google search turned up a bunch of pages, none of which I could understand enough to be of help. So, any pointers would be appreciated. Thanks! Jason Soza -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 11:01 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Re: Using fopen()/fread()/fscanf() On Tuesday 23 July 2002 14:16, Jason Soza wrote: 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. Not sure why you're using fscanf() and why it doesn't work. I would use preg_match() on $contents. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Communications satellite used by the military for star wars. */ -- 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
Re: [PHP] Re: Using fopen()/fread()/fscanf()
On Tuesday 23 July 2002 15:38, Jason Soza wrote: Alright, I see that this is probably the way to go, but I'm dying here. I have this: $filename = fopen(http://www.kinyradio.com/juneaunews/latest_juneau_news.html;, r); $contents = fread($filename, 100); preg_match_all(|font face=\Verdana\ size=\3\b+[-a-zA-Z0-9,. ]+|i, $contents, $out); print_r($out); Assuming that the font and b tags are closed and you want everything in between then try this: preg_match_all(|font face=\Verdana\ size=\3\b(.*)/b/font|i, $contents, $out); The manual entries for preg_match and preg_match_all pretty much assume you have a working knowledge of reg expressions, which I don't, and a google search turned up a bunch of pages, none of which I could understand enough to be of help. So, any pointers would be appreciated. Thanks! You want to read up on Pattern Modifiers and Pattern Syntax, that's where all the regex black magic is explained. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* He's dead, Jim. -- McCoy, The Devil in the Dark, stardate 3196.1 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Using fopen()/fread()/fscanf()
I must be dumb because I still can't get it to work. Using the following instead of my previous preg_match_all statement: preg_match_all(|font face=\Verdana\ size=\3\b(.*)/b/font|i, $contents, $out); Gives me only the -last- 3 headlines on http://www.kinyradio.com/juneaunews/latest_juneau_news.html. I've looked at the source and there are indeed more matching tags than are being returned. I've tried placing r+ in my fopen() statement to put the pointer at the beginning of the file, but no luck there. I've also tried a bigger filesize constant in fread(), still nothing. Actually, I just noticed what the difference is with those last three - their lines don't break in the source. The other lines have breaks, so the /b/font land on the following line. Is there anything I can do to have preg_match_all 'connect' the lines? Any help would be great. Thanks! Jason Soza -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 23, 2002 1:20 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Re: Using fopen()/fread()/fscanf() On Tuesday 23 July 2002 15:38, Jason Soza wrote: Alright, I see that this is probably the way to go, but I'm dying here. I have this: $filename = fopen(http://www.kinyradio.com/juneaunews/latest_juneau_news.html;, r); $contents = fread($filename, 100); preg_match_all(|font face=\Verdana\ size=\3\b+[-a-zA-Z0-9,. ]+|i, $contents, $out); print_r($out); Assuming that the font and b tags are closed and you want everything in between then try this: preg_match_all(|font face=\Verdana\ size=\3\b(.*)/b/font|i, $contents, $out); The manual entries for preg_match and preg_match_all pretty much assume you have a working knowledge of reg expressions, which I don't, and a google search turned up a bunch of pages, none of which I could understand enough to be of help. So, any pointers would be appreciated. Thanks! You want to read up on Pattern Modifiers and Pattern Syntax, that's where all the regex black magic is explained. -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* He's dead, Jim. -- McCoy, The Devil in the Dark, stardate 3196.1 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 8:37 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: Using fopen()/fread()/fscanf() In article [EMAIL PROTECTED], [EMAIL PROTECTED] 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, 100); 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/abr; 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
RE: [PHP] Re: Using fopen()/fread()/fscanf()
I'm thinking that you need to remove the: $contents = fread($filename, 100); 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 result. Thanks, Jason Soza -Original Message- From: David Robley [mailto:[EMAIL PROTECTED]] Sent: Monday, July 22, 2002 8:37 PM To: [EMAIL PROTECTED] Subject: [PHP] Re: Using fopen()/fread()/fscanf() In article [EMAIL PROTECTED], [EMAIL PROTECTED] 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, 100); 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/abr; 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php