string - php 俄语字符的不区分大小写比较

标签 string comparison case

如何不区分大小写地比较俄语字符。 我尝试过:

if(strcasecmp($content->title, 'О нас') == 0){
        $about=$content->title;
    }

还有

if(strtolower($content->title) == strtolower('О Нас')){
        $about=$content->title;
    }

两者都不起作用。如果我将两个字符串放在同一个“case”中,它将返回 true,否则返回 false。 $content->title 从 Mysql 数据库返回“О Нас”,第二个字符串也是“О Нас”,但如果我创建第二个字符串“О нас”并使用上述比较之一,它会返回 false,为什么?有什么建议吗?

最佳答案

我不知道为什么,但使用 mb_strtolower 找到了一个可行的解决方案功能:

mb_strtolower($content->title) == mb_strtolower('О Нас')

我对为什么第一个选项不起作用的猜测:

来自strtolower文档:

Note that 'alphabetic' is determined by the current locale. This means that e.g. in the default "C" locale, characters such as umlaut-A (Ä) will not be converted.

来自mb_strtolower文档:

By contrast to strtolower(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).

还要确保两个可比较的字符串使用相同的编码(字符串文字使用源文件编码),或者您可以使用 mb_strtolower 函数的第二个参数来设置每个字符串的编码。

关于string - php 俄语字符的不区分大小写比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11914158/

相关文章:

c - 搜索 vector 中出现两次的所有整数

mysql - 添加 SQL Case 以在更新查询中提供默认值

sql-server - sql server 中的 CASE - 实现澄清?

c - C 中的 scanf string 和 printf 不能按预期工作

c - -1 不小于 12?

MYSQL - 插入连接字符串

python - python 中区分大小写的路径比较

c - 从字符串中删除扩展名和目录?

Mysql查询比价

sql - 如果子查询导致SQLite情况