最新消息: 新版网站上线了!!!

php strpos(), stripos(),strrpos(), strripos()的区别

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";

}?>   

  1. We found 'a' in 'axyz' at position 0   

  2. We found 'a' in 'BCaaaA' at position 5

转载请注明:谷谷点程序 » php strpos(), stripos(),strrpos(), strripos()的区别