就像问题所说的一样:
有没有一种方法可以调用不区分大小写的 substr_count() 函数?
就像问题所说的一样:
有没有一种方法可以调用不区分大小写的 substr_count() 函数?
没有本地方法,你可以这样做:
substr_count(strtoupper($haystack), strtoupper($needle));
当然,你可以将其编写为一个函数:
function substri_count($haystack, $needle)
{
return substr_count(strtoupper($haystack), strtoupper($needle));
}
在使用大小写更改来比较字符串时,请注意土耳其测试。
http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
从上面的内容可以看出:
正如许多人所讨论的那样,土耳其语中的"I"与大多数语言不同。根据Unicode标准,我们的小写"i"在变成大写时变为"İ"(U+0130 "带点的拉丁大写字母I")。同样地,我们的大写"I"在变成小写时变为"ı"(U+0131 "无点的拉丁小写字母i")。
简单:将两个字符串强制转换为小写:
substr_count(strtolower($haystack), strtolower($needle));
在计数之前执行 strtolower
。