dongpao1926 2013-02-13 16:28
浏览 25
已采纳

我应该如何使用htmlentities来显示utfó(而不是³)

I'm writing a small newsletter in PHP

I'm using PHP's htmlentities($str) so I'll have no problems with encoding in client's email.

This $str is coming out of mysql.

I see ó when it's supposed to be a ó in the client.

I'm also writing some text in the newsletter where I echo "ó"; and I see it in the client as ó.

Then I suppose that I have to make some treatment to $str before appliyng the htmlentities but I don't understand what should I do.

How can I know what is wrong with (what treatment should I do to) $str?

  • 写回答

1条回答 默认 最新

  • douzhan8652 2013-02-13 16:47
    关注

    This solves the issue

    https://stackoverflow.com/a/10539209/912450

    //You must manually specify the encoding (UTF-8) for htmlentities()
    echo htmlentities($str, null, "UTF-8");
    

    The problem seems to be (according to documentation) that if UTF-8 is not specified, in PHP versions prior to 5.4.0, ISO-8859-1 is the default encoding for htmlentities.

    If $str is UTF8 encoded then it will only work ok in PHP>=5.4.0, where UTF-8 is the default encoding for htmlentities if no encoding is specified.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思