hellonoko Posted March 28, 2006 Share Posted March 28, 2006 I need to go through a list of words and find ones with certain letters in the last two places.I know how to code this but am not sure of what str functions I would use.I am looking around a little in the PHP manual can anyone point me in the right direction?Also my host does not support the php5 fuction stream_get_contents() What would be an alternative function for getting the contects of a HTML page and processing them in my php page.Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/ Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 How is your list of words setup? Is it an array? Is it all in a string? I'd use the substr() function to look at the words and determine if it matches your pattern.I would use fopen() for that, but I'm going to guess that you're not allowed to use that function either... but maybe. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21582 Share on other sites More sharing options...
hellonoko Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359281:date=Mar 28 2006, 10:08 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 10:08 AM) [snapback]359281[/snapback][/div][div class=\'quotemain\'][!--quotec--]How is your list of words setup? Is it an array? Is it all in a string? I'd use the substr() function to look at the words and determine if it matches your pattern.I would use fopen() for that, but I'm going to guess that you're not allowed to use that function either... but maybe.[/quote]the list of word will be put into an array.does fopen() work for remote files and urls as well as files on the server? Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21584 Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 [code]<?phpfor($i = 0; $i < count($myarray); $i++){ if(substr($myarray[i], -2) == 'ab') // do something} [/code]And yes, fopen() opens both remote and local files. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21587 Share on other sites More sharing options...
hellonoko Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359286:date=Mar 28 2006, 10:16 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 10:16 AM) [snapback]359286[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?phpfor($i = 0; $i < count($myarray); $i++){ if(substr($myarray[i], -2) == 'ab') // do something} [/code]And yes, fopen() opens both remote and local files.[/quote]when i use fopen() to open a URL i get only:Resource id #4I asume it is opening the page but not putting the acctually contents into my varriable. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21593 Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 Exactly. That's because fopen() returns a file handle number. You need to use fread() to actually read the contents of the file.You could also use fgets() in a loop. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21615 Share on other sites More sharing options...
hellonoko Posted March 28, 2006 Author Share Posted March 28, 2006 [!--quoteo(post=359315:date=Mar 28 2006, 11:42 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 28 2006, 11:42 AM) [snapback]359315[/snapback][/div][div class=\'quotemain\'][!--quotec--]Exactly. That's because fopen() returns a file handle number. You need to use fread() to actually read the contents of the file.You could also use fgets() in a loop.[/quote]i had to use file_get_contents()but i got it working.thanks! Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21630 Share on other sites More sharing options...
ober Posted March 28, 2006 Share Posted March 28, 2006 Yeah... that'll work too... I forgot about that function. Quote Link to comment https://forums.phpfreaks.com/topic/6011-parsing-strings/#findComment-21632 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.