【发布时间】:2025-12-11 17:30:02
【问题描述】:
$string = 'operating-system';
$array = array('operating-system');
$i = contains($array, $string);
echo ($i) ? "found ($i)" : "not found";
上面的代码打印 found(1)
$string = '운영체제';
$array = array('운영체제');
$i = contains($array, $string);
echo ($i) ? "found ($i)" : "not found";
但是这段代码打印出not found。为什么?
我已更新 charset=utf-8
function contains($needles, $haystack) {
return count(array_intersect($needles, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $haystack))));
}
【问题讨论】:
-
请告诉我们
contains的代码 -
@Rizier123:更新
-
所以当我阅读您的代码时,您使用空格作为单词分隔符并想从字符串中搜索数组中有多少单词,对?