且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转换带有重音符号的外来字符

更新时间:2023-02-26 09:58:37

您需要将正确的字符集发送到htmlentities.看起来您正在使用UTF-8,但默认值为ISO-8859-1.像这样更改它:

You need to send in the correct charset to htmlentities. It looks like you're using UTF-8, but the default is ISO-8859-1. Change it like this:

$encoded = htmlentities($text, ENT_COMPAT, 'UTF-8');

另一种解决方案是在编码之前将文本转换为ISO-8859-1,但这可能会破坏信息(ISO-8859-1包含的字符几乎不及UTF-8那样多).如果您想尝试一下,请执行以下操作:

Another solution is to convert the text to ISO-8859-1 before encoding, but that may destroy information (ISO-8859-1 does not contain nearly as many characters as UTF-8). If you want to try that instead, do like this:

$encoded = htmlentities(utf8_decode($text));