Which method is preferred strstr or strpos?

johnlemon picture johnlemon · Apr 28, 2011 · Viewed 50.2k times · Source

I noticed a lot of developers are using both strstr and strpos to check for a substring existence. Is one of them preferred and why ?

Answer

Alnitak picture Alnitak · Apr 28, 2011

From the PHP online manual:

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