Home  >  Article  >  Backend Development  >  Intercept string PHP determines the characters and the containing method attributes of the string

Intercept string PHP determines the characters and the containing method attributes of the string

WBOY
WBOYOriginal
2016-07-29 08:38:411060browse

The usage method is introduced below:
1. strstr: Returns a string from the beginning to the end of the judged character. If there is no return value, it does not contain

Copy code The code is as follows:


/*As shown 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 not case-sensitive.
3. strpos: Returns a boolean value. Needless to say, FALSE and TRUE. Use "===" Judgment.strpos is faster than the above two functions in terms of execution speed. In addition, strpos has a parameter to specify the position of judgment, but the default is empty. It means to judge the entire string. The disadvantage is that it does not support Chinese well. How to use

Copy the code The code is as follows:


$str= 'abc';
$needle= 'a';
$pos = strpos($str, $needle);


4. Use explode to judge

Copy the code The code is as follows:


function checkstr($str){
$needle = "a";//Determine whether the character a is included
$tmparray = explode($needle,$str);
if(count($tmparray)>1){
return true;
} else{
return false;
}
}


The above introduces how to intercept strings, PHP determines characters and the containing method attributes of strings, including the content of intercepting strings. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn