php – htmlentities和é(急性)

前端之家收集整理的这篇文章主要介绍了php – htmlentities和é(急性)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到了 PHP的htmlentities和é字符的问题.我知道这是一种我只是忽略的编码问题,所以希望有人能看出我做错了什么.

运行直接的htmlentities(“é”)并没有按预期返回正确的代码(é或& eacute;.我试过强制charset为’UTF-8′(使用charset参数) 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);
原文链接:https://www.f2er.com/php/137795.html

猜你在找的PHP相关文章