我的 PHP 有问题htmlentities
和 é 字符。我知道这是我忽略的某种编码问题,所以希望有人能看到我做错了什么。
跑直道htmlentities("é")
没有按预期返回正确的代码(或者é
or é
。我尝试过强制将字符集设置为“UTF-8”(使用 htmlentities 的字符集参数),但效果是一样的。
最终目标是通过以“ISO-8859-1”编码的 HTML 电子邮件发送该字符。当我尝试将其强制编码时,同样的问题。在电子邮件的来源中,您会看到 é,在 HTML 视图中é
.
谁能解释一下我的错误?
// I assume that your page is utf-8 encoded
header("Content-type: text/html;charset=UTF-8");
$in_utf8encoded = "é à ù è ò";
// first you need the convert the string to the charset you want...
$in_iso8859encoded = iconv("UTF-8", "ISO-8859-1", $in_utf8encoded);
// ...in order to make htmlentities work with the same charset
$out_iso8859= htmlentities($in_iso8859encoded, ENT_COMPAT, "ISO-8859-1");
// then only to display in your page, revert it back to utf-8
echo iconv("ISO-8859-1", "UTF-8", $out_iso8859);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)