Home  >  Article  >  php教程  >  PHP stripos()函数及注意事项的分析

PHP stripos()函数及注意事项的分析

WBOY
WBOYOriginal
2016-06-13 11:49:251260browse

定义和用法
stripos() 函数返回字符串在另一个字符串中第一次出现的位置。

如果没有找到该字符串,则返回 false。

语法
stripos(string,find,start)

参数 描述
string 必需。规定被搜索的字符串。
find 必需。规定要查找的字符。
start 可选。规定开始搜索的位置。

提示和注释
注释:该函数对大小写不敏感。如需进行对大小写敏感的搜索,请使用 strpos() 函数。
由于此函数返回的是返回字符串在另一个字符串中第一次出现的位置。所以这个位置有可能是0
那么当返回值为0的时候就需要注意

复制代码 代码如下:


if(stripos($r, 'a') == false) {

       //0是a存在与$r总但是由于0和false是相等的,所以就执行了这里
}
if(stripos($r, 'a') === false) {

     // 这种情况我们必须使用全等于才行

}


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