What is an efficient way to find if $string1 contains the string "email or Email"?
Initially I was thing of:
if (substr_count($string1, "email") || substr_count($string1, "Email")
{
....
}
but is there a better way? (Just trying to add to my PHP education)
Searching for string within a string?
Moderator: General Moderators
Re: Searching for string within a string?
while JAM's solution is tottaly valid, the "efficient way" would be using
In this regard, even when you replace a string it's good practice (faster) to first check if the string to replace exists at all - using strpos.
Code: Select all
strpos()Re: Searching for string within a string?
Thanks for that.jmut wrote:while JAM's solution is tottaly valid, the "efficient way" would be usingIn this regard, even when you replace a string it's good practice (faster) to first check if the string to replace exists at all - using strpos.Code: Select all
strpos()
Re: Searching for string within a string?
Of course are you right! It was me that posted the incorrect address for some odd reason.jmut wrote:while JAM's solution is tottaly valid, the "efficient way" would be usingIn this regard, even when you replace a string it's good practice (faster) to first check if the string to replace exists at all - using strpos.Code: Select all
strpos()