php字符串匹配函数比较区别php strpos() stripos() strrpos() strripos()

2014年9月30日 发表评论 阅读评论

strpos(), 左边开始,字符出现第一个位置,区分大小写;
stripos(),不区分大小写;
strrpos(), 左边开始,字符出现,最后一个位置,区分大小写;
strripos()不区分大小写;
$findme = ‘a’;
$mystring1 = ‘axyz’;
$mystring2 = ‘BCaaaA’;
$pos1 = strpos($mystring1, $findme);
$pos2 = strripos($mystring2, $findme);
if ($pos1 === false)
{  
echo "The string ‘$findme’ was not found in the string ‘$mystring1′<br />";
}
else{  
echo "We found ‘$findme’ in ‘$mystring1′ at position $pos1<br />";
}
if ($pos2 !== false) {    
echo "We found ‘$findme’ in ‘$mystring2′ at position $pos2";
}?>  
We found ‘a’ in ‘axyz’ at position 0  
We found ‘a’ in ‘BCaaaA’ at position 5


转载请注明来自:[MSN Spaces]http://msn.shandian.biz/811.html

  1. 本文目前尚无任何评论.