douyao4632 2012-08-09 10: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 11: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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程