Jump to content

parsing strings


hellonoko

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.
Link to comment
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.
Link to comment
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?

Link to comment
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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.