Jump to content

Recommended Posts

I need to scan a page for certain words. If the page has those words, then i want to perform a certain action and if not, then a different action. However, I don't need all of the words to be present on the page, just one of them.

 

How would I do that?

 

For example, if the words that I wanted to look for are:

 

Green

Blue

Red

 

and $result contained:

 

The blue cat was big.

 

I want if(preg_match.....

 

to say yes even though red and green weren't present.

 

Would I use preg_match or preg_match_all or something else? I basically need like an 'OR' between the terms I am looking for in $result.

Link to comment
https://forums.phpfreaks.com/topic/201817-scanning-a-page/
Share on other sites

might have to benchmark it and it certainly depends on how big the subject is (and in the end of the day diff might be too small to care...) but in general if you are just wanting to check a string within a string (not looking to match a pattern) the built-in string search functions are faster.  strpos, stripos, strstr or stristr, etc...

Link to comment
https://forums.phpfreaks.com/topic/201817-scanning-a-page/#findComment-1059846
Share on other sites

  • 3 weeks later...
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.