Finding if a string occurs in another string

Options:
1) strpos
2) strstr

If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead of strstr.

For case insensitive queries, use stripos and stristr

strstr: Returns part of haystack string starting from and including the first occurrence of needle to the end of haystack. Has option in new version of PHP to return part of string before needle also. Returns false if not found.

strpos: Find the numeric position of the first occurrence of needle in the haystack string.
Returns false if not found.

Leave a Reply