The inclusion of the PHP judgment string

Source: Internet
Author: User
Tags explode php language

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.