问题描述
我对utf8_encode / utf8_decode PHP函数有问题。该函数必须是互补的。
我知道:
- utf8_decode将UTF8字符串转换为ISO-8859-1
- utf8_encode将ISO-8859-1转换为UTF8
但是,如果我尝试转换并返回字符左双引号,则行为会有所不同。 我希望这两个回显可以打印相同的字符,但这不会发生。
<?PHP
$doubleQuote = hex2bin("e2809c");
var_dump($doubleQuote);
$doubleQuoteNew = utf8_encode(utf8_decode($doubleQuote));
var_dump($doubleQuoteNew);
这是输出
/tmp/test.PHP:3:
string(3) "“"
/tmp/test.PHP:5:
string(1) "?"
不是使用简单字符,而是两个回声返回相同的值。 我尝试使用PHP版本5和7。
我的错在哪里??
解决方法
拉丁语1编码does not contain any "fancy quote" character。 Unicode “
字符没有可转换为Latin-1的等效字符,因此将其替换为?
。这样就可以完美地转换回UTF-8。