PHP中如何判断字符串中是否含有指定字符或字符串?

已邀请:

zkbhj - 凯冰科技站长

赞同来自:

速度最高的应该是strpo函数,查找特定字符串的位置:
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);

// 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作,
// 因为 'a' 是第 0 位置上的(第一个)字符。
if ($pos === false) {
echo "没有找到 '$findme' 在 '$mystring' 中。";
} else {
echo "找到 '$findme' 在 '$mystring' 中,位置是 $pos";
}
?>

要回复问题请先登录注册