Search for a string in a variable---

Is there a way to find a particular string in php.

For example:

I want php to echo "Found" if the word "sports" in found in this url

if not then it should echo "bad Luck"

Is there any pre-defined function for this in php?


preg_match sounds like what you want.

More info can be found here:

Good luck!

You can use preg_match if you're going to search for a pattern in a string.

However, if you're going to look for just a string, then you should use a function such as strstr() or stristr()

eg: case sensitive

if (strstr('', 'sports')) {
   echo 'found';
} else {
   echo 'not found';

preg_match() is much slower than strstr() and also uses more resources as it matches a pattern.