【发布时间】:2017-06-16 07:19:38
【问题描述】:
我有两个字符串变量 - 第一个变量是在代码中手动设置的 ($date1="14 июня"),第二个变量是使用 cURL 和 phpQuery 从远程页面解析的。
如果我们打印两个变量,结果看起来一样,但长度和内容不同:
echo $date1; //output: 14 июня
echo $date2; //output: 14 июня
echo $date1[2]; //output is space - third symbol in string
echo $date2[2]; //output is � - it's a part of third symbol in string
echo strlen($date1); //output: 7
echo strlen($date2); //output: 12
echo mb_detect_encoding($date1) //output: UTF-8
echo mb_detect_encoding($date2) //output: UTF-8
我想知道是否有解决方案如何将$date2 转换为$date1 的格式/编码?
p.s:有关于 iconv() 的 SO 主题,但我无法找到可行的解决方案。
【问题讨论】:
-
那里还有不可见的字符。两者都显示
echo bin2hex($s)。 -
用
var_dump(array_shift(unpack('H*', $dateX)));这样的表达式转储变量 -
3134204a756e65是14 June,313420d0b8d18ed0bdd18f是14 июня。 -
那么,你不能比较它们,看看后者有额外的
c2a0字节,而前者使用20作为空格? -
这只是一种不同类型的空间。这取决于你用它做什么。 fileformat.info/info/unicode/char/00a0/index.htm
标签: php encoding utf-8 multibyte