$string = 'operating-system';
$array = array('operating-system');
$i = contains($array, $string);
echo ($i) ? "found ($i)" : "not found";
上面的代码打印,找到(1)
$string = '운영체제';
$array = array('운영체제');
$i = contains($array, $string);
echo ($i) ? "found ($i)" : "not found";
但是这段代码打印的是没有找到。为什么?
我更新了字符集=utf-8
function contains($needles, $haystack) {
return count(array_intersect($needles, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $haystack))));
}
发布于 2016-04-07 23:32:59
您需要一个支持多字节字符的本地函数。而不是preg_replace
,您可以使用替换。
function contains($needles, $haystack) {
return count(array_intersect($needles, explode(" ", mb_ereg_replace("/[^A-Za-z0-9' -]/", "", $haystack))));
}
您还可能希望查看所有多字节字符串函数的文档。
https://stackoverflow.com/questions/36488927
复制相似问题