Jump to content

How To Find Keywords In A String


standers
 Share

Recommended Posts

Can someone please tell me how for find more than one keyword in a string?I'm new at php so a little help would be greatly appreciated. I have read the php manual on strpos at http://www.php.net/manual/en/function.strpos.phpbut I can't find out how to search a string for more than one word.<?php$mystring = 'pets';$findme = 'dog';$pos = strpos($mystring, $findme);but I would like to have $findme = 'dog'; also search for cat, dog, birdthank you for any help you can provide.

Link to comment
Share on other sites

If you want to find the first position for any of "cat", "dog" or "bird", then you can do three calls to strpos(), one for each, and then find out which result is the smallest (you could automate this using a loop). For more complex situations, maybe have a look at regular expressions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...