dongtuwu8548 2014-04-03 11:40
浏览 44
已采纳

PHP中的htmlspecialchars完全在XML输出中省略了数据

I have a MySQL query that returns data for formatting to an XML file. One of the columns is a free text field that can contain strange characters that "breaks" the XML with an encoding error. I believe these characters are a strange " quotes that made it into a record from pasted Microsoft Word when the user originally input the record. I do not have control over that process.

Strange Character example:

“TURN KEY – Totally Furnished†

I am using htmlspecialchars to "clean" this data and it basically removes the field entirely from XML record and makes it blank for that record. This fixes the encoding issue but that record is now missing data for that field. I still want that data, I just want to omit or even change weird characters to something like a dash.

$description  = htmlspecialchars($row['PropertyInformation'], ENT_QUOTES, 'UTF-8');

The XML output ends up like this in the records where the weird characters are occurring:

<DESCRIPTIF>
<![CDATA[ ]]>
</DESCRIPTIF>
  • 写回答

3条回答 默认 最新

  • dongmin4052 2014-04-06 11:11
    关注

    The htmlspecialchars function returns an empty string if the input string contains an invalid code unit sequence within the given encoding, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

    The ENT_IGNORE flag silently discards invalid code unit sequences instead of returning an empty string. Using this flag is discouraged as it may have security implications.

    The ENT_SUBSTITUTE falg replaces invalid code unit sequences with a Unicode Replacement Character U+FFFD (UTF-8) or &#FFFD; (otherwise) instead of returning an empty string.

    You could try to set one of these flags.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?