【问题标题】:Mysql and PHP strings comparison - Unicode normalization?Mysql 和 PHP 字符串比较 - Unicode 规范化?
【发布时间】:2016-08-29 23:25:34
【问题描述】:

我目前在 PHP 和 Mysql 字符串之间的字符串比较方面遇到了一些问题。 我有一个来自 Mysql 数据库的变量,我将它与一个硬编码的变量进行比较:

$string_from_mysql = "Información" //comes from DB read;
$test_string = "Información" //hard coded via text editor;
$test = strpos($string_from_mysql,$test_string); -> Returns false

问题似乎与ó有关,在$string_from_mysql 中,该字符的值为0x00F3,而在$test_string 中,该字符为0xC3 0xB3。 显然,这会导致 strpos 的“假”返回值。该字符是“规范等效的”,但它没有相同的值。

在这种情况下有什么方法?我发现了 Normalizer PHP 类,它是唯一可行且干净的解决方案吗?

谢谢。

【问题讨论】:

标签: php mysql unicode normalization


【解决方案1】:

正如nwellnhof 所说,在连接上设置字符集解决了这个问题。就我而言,我不得不使用mysql_set_charset

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-28
    • 2021-03-30
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 2011-12-10
    • 2018-04-16
    相关资源
    最近更新 更多