dousi6405 2012-05-04 12:44
浏览 8
已采纳

是否有PHP函数将数据库中突出显示的字母转换为html代码?

There is a MySQL database containing data with accentuated letters like é. I want to display it in my PHP page , but the problem is that there are unrecognized characters displayed because of the accent. So is there a function to convert accent to HTML code , for example é is converted to é !

  • 写回答

4条回答 默认 最新

  • duanqianruan8448 2012-05-04 12:49
    关注

    Rather than using htmlentities you should use the unicode charset in your files, e.g.

    <?php
    header('Content-Type: text/html; charset="utf-8"');
    

    To be on the safe side, you can add the following meta tag to your html files:

    <html>
      <head>
        <meta charset="utf-8" />
    

    Then, make sure that your data base connection uses utf8:

    mysql_connect(...);
    mysql_select_database(...);
    
    mysql_set_charset('utf-8');
    

    Then, all browsers should display the special characters correctly.

    The advantage is that you can easily use unicode characters everywhere in your php files - for example the copyright sign (©) or a dash (–) - given that your php files are encoded in utf-8, too.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了