Provides various official and user-released code examples. For code reference, you are welcome to learn about the inclusion of PHP judgment strings.
PHP is a powerful embedded HTML scripting language. its ease of use allows many programmers to choose to use it. PHP can use the built-in strstr, strpos, and stristr functions of PHP to determine the inclusion of a string. You can also use the explode function to write a judgment function.
1. strstr: returns a string from the start to the end of the character to be judged. If no return value exists, it does not contain
The Code is as follows:
<? Php
/* Example in the manual */
$ Email = 'user @ example.com ';
$ Domain = strstr ($ email ,'@');
Echo $ domain;
// Prints @ example.com
?>
2. stristr: It is used exactly the same as strstr. The only difference is that stristr is case insensitive.
3. strpos: returns a boolean value. FALSE and TRUE. use "=" to judge. the execution speed of strpos is faster than that of the above two functions. In addition, strpos has a parameter that specifies the location for judgment, but is left blank by default. it indicates determining the entire string. the disadvantage is poor support for Chinese characters.
PHP judges that the string contains the following code:
$ Str = 'abc ';
$ Needle = 'a ';
$ Pos = strpos ($ str, $ needle );
4. Use explode for determination
PHP judges that the string contains the following code:
Function checkstr ($ str ){
$ Needle = "a"; // determines whether the string contains.
$ Tmparray = explode ($ needle, $ str );
If (count ($ tmparray)> 1 ){
Return true;
} Else {
Return false;
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB