php strpos 与mb_strpos的区别

$a = '歪麦博客';
$b = '博客';
$pos = strpos($a, $b);
echo $pos;//6
echo "
";

$pos = mb_strpos($a, $b);
echo $pos;//2
echo "
";

$pos = strpos(mb_convert_encoding($a, 'utf-8'), mb_convert_encoding($b, 'utf-8'));
echo $pos;//6
echo "
";
$submit = "我爱北京天安门";
$item = "天安门";
echo mb_strpos($submit, $item); //4
echo "
";
var_dump(strpos('开始23测试ceshi', '测试'));//8
echo "
";
 var_dump(mb_strpos('开始23测试ceshi', '测试'));//4
echo "
";
var_dump(strpos('123测试ceshi', '测试'));//3
echo "
";
var_dump(mb_strpos('123测试ceshi', '测试'));//3

mb_strpos 按字处理,strpos 按字符处理

strpos如果查找的字符串是 【汉字】,那么长度就以 utf-8格式,记3,;

strpos如果查找的字符串是【非汉字】,那么长度记 1 ;

你可能感兴趣的:(php)