Mic*_*yen 8 php character-encoding html-entities
我遇到了PHP htmlentities和é角色的问题.我知道这是一种我只是忽略的编码问题,所以希望有人能看出我做错了什么.
运行直接htmlentities("é")不会按预期返回正确的代码(é或者é.或者我已经尝试将charset强制为'UTF-8'(使用htmlentities的charset参数)但是同样的事情.
最终目标是将此字符发送到以"ISO-8859-1"编码的HTML电子邮件中.当我试图强制它进入该编码时,同样的问题.在电子邮件的来源中,您会看到é,并在HTML视图中é.
谁可以解释我的错误?
小智 12
// 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);
Run Code Online (Sandbox Code Playgroud)