douyao4632 2012-08-09 02:59
浏览 66
已采纳

当使用PHP从MSSQL数据库读取时,Diaeresis显示为问号

I have a bit of PHP that gets data from a MSSQL database and saves it to an array:

while($row = mssql_fetch_array($dbquery, MSSQL_NUM)) 
{
    $content = array(
        'something'         =>  $row[1],
        'something_else'    =>  $row[2]
        // etcetera
    );
}

(The reason why I write the data to an array like that is not relevant I think, but if you must know: it is because the data is parsed by ExpressionEngine (EECMS). The PHP code is part of a plugin I am developing and this is the easiest way to make the data available for use in ExpressionEngine tags.)

Some of the data in de MSSQL database contains punctuated characters, such as ë and é. The diaeresis (ë) are shown as question marks in the HTML. For instance, Cliënten is shown as Cli�nten.

The HTML is in UTF8: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

I cannot change anything in the MSSQL database. What is the best way, preferably in PHP, to fix this?

  • 写回答

1条回答 默认 最新

  • dqwh1119 2012-08-09 03:33
    关注

    When you see question marks like that, it means your browser is having trouble understanding what the character the question mark has replaced is supposed to represent. Most likely, it is expecting utf8 character encodings and is not getting them.

    Try running something like this on your array (after it's built) and see if that helps:

    $content = array_map('utf8_encode', $content);
    

    Basically you want to run the utf8_encode() function on all the strings that come out of the database since apparently they are not encoded as such in the database.

    You could also run the utf8_encode function immediately before you output each variable. So something like:

    <p><?php echo utf8_encode($content_row) ?></p>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部