dongmo1708 2011-02-27 23:59
浏览 162
已采纳

PHP中的UTF-8和ISO 8859-1编码

I am trying to convert all   instances to regular spaces in PHP:

echo '<meta charset="UTF-8" /> ';
echo html_entity_decode('&nbsp;');
echo html_entity_decode('&nbsp;', ENT_COMPAT, 'UTF-8');

If the first line is commented out, then the output will be in ISO 8859-1 and read:

 Â

Where there is a space in front. If UTF-8 encoding is specified, it reads:

Which is an undefined UTF-8 character followed by a space. Is there anyway to ensure that all HTML entity spaces are correctly decoded regardless of the encoding?

The space character is really just an example, what I am trying to do is read html input from an unspecified charset and display it. So < and &#60; would both become <.

  • 写回答

3条回答 默认 最新

  • duanjing7651 2011-02-28 00:38
    关注

    This is problem with encodings. They are not compatible. You have to use different options in html_entity_decode for every encoding. However, You may convert input to utf-8 (iconv) first and use html_entity_decode($string, ENT_COMPAT, 'UTF-8') later.

    If You don't know the encoding of input, You have to guess.

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

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私