The PHP language is a powerful embedded HTML scripting language, and its ease of use allows many programmers to choose. PHP to determine the inclusion of a string, you can use the PHP built-in function strstr,Strpos, STRISTR directly to judge.You can also write a judgment function by the function of explode. 1.strstr: Returns a string from the beginning of the judged character to the end, if there is no return value,the code below is not included:<?PHP/*as illustrated in the manual*/$email= ' [email protected] ';$domain=strstr($email, ‘@‘);Echo $domain;//prints @example. com?>
2.Stristr: It is exactly the same as strstr. The only difference is that the STRISTR is not case sensitive.
3.Strpos: Returns a Boolean value. False and true do not say much. use "= = =" to judge. Strpos is faster than the above two functions in execution speed, and Strpos has a parameter to specify the location of the judgment, but the default is empty. Meaning to judge the entire string. The disadvantage is that the support for Chinese is not good.PHP judgment string contains the following code:$str= ' abc ';$needle= ' A ';$pos=Strpos($str,$needle);
4.using explode to determine the PHP judgment string contains the following code:functionCHECKSTR ($str){$needle= "a";//determine if a character is included$tmparray=Explode($needle,$str);if(Count($tmparray) >1){return true;} Else{return false;}}
The inclusion of the PHP judgment string