精美而实用的网站,关注web编程技术、网站运营、SEO推广,让您轻松愉快的学习

stripos() 函数返回字符串在另一个字符串中第一次出现的位置。它与strpos()函数的区别是, stripos() 函数不区分字符串大小写,而strpos()则是区分大小写的,因此请根据你的实际情况在两者之间选择。

若你不要求大小写,二者都可使用,但使用stripos() 时,你需要使用strtolower()函数将字符串统一转换为小写,或使用strtoupper()统一转换成大写。

stripos()函数用法示例

<?php
$findme = 'n';
$mystring1 = 'hjk';
$mystring2 = 'And';
$pos1 = stripos($mystring1, $findme);
$pos2 = stripos($mystring2, $findme);
if ($pos1 === false) {
    echo "字符'$findme'并不在字符串'$mystring1'中<br>";
}
if ($pos2 !== false) {
    echo "但找到'$findme'在'$mystring2'中,位置为:$pos2";
}
?>

青岛星网温馨提醒:在stripos() 函数中,查找到的位置是从0开始计算的,也就说,要找的字符在第一位,那么函数将显示“0”。

Tags:PHP stripos() 字符串