Jump to content

Archived

This topic is now archived and is closed to further replies.

hellonoko

parsing strings

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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?

Share this post


Link to post
Share on other sites
[code]<?php
for($i = 0; $i < count($myarray); $i++)
{
     if(substr($myarray[i], -2) == 'ab')
          // do something
} [/code]

And yes, fopen() opens both remote and local files.

Share this post


Link to post
Share on other sites
[!--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]<?php
for($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 #4

I asume it is opening the page but not putting the acctually contents into my varriable.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--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!

Share this post


Link to post
Share on other sites
Yeah... that'll work too... I forgot about that function.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.