加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – htmlentities和é(急性)

发布时间:2020-12-13 13:33:12 所属栏目:PHP教程 来源:网络整理
导读:我遇到了 PHP的htmlentities和é字符的问题.我知道这是一种我只是忽略的编码问题,所以希望有人能看出我做错了什么. 运行直接的htmlentities(“é”)并没有按预期返回正确的代码(#233;或 eacute;.我试过强制charset为’UTF-8′(使用charset参数) 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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读