PHP determines characters and the inclusion method attributes of strings_PHP tutorial

WBOY
Release: 2016-07-21 15:49:53
Original
791 people have browsed it

The following describes how to use:

1. strstr: Returns a string from the beginning to the end of the judged character. If there is no return value, it does not include

Copy the 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 the support for Chinese is not good. How to use

Copy code The code is as follows:

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

4. Use explode to judge

Copy 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;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319442.htmlTechArticleThe following describes how to use it: 1. strstr: Returns a string from the beginning to the end of the character being judged, if there is no The return value does not include the copy code. The code is as follows: ?php /*As shown in the manual...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!