WordPress在帖子内容中错误地显示了HTML实体和十六进制实体

时间:2019-01-22 15:49:31

标签: php xml wordpress utf-8 character-encoding

我将以下代码保存为运行TwentyNineteen主题的未经修改的Wordpress安装中的帖子内容。它包含HTML实体和十六进制实体的组合。

<span>Explore the professions of some of the groundbreaking women in 
science, technology, engineering and mathematics (STEM) with the LEGO&Acirc;&reg; Ideas Women of NASA set. It features minifigures of 4 pioneering women of NASA&acirc;&#8364;&#8221; astronomer and educator Nancy Grace Roman, computer scientist and entrepreneur Margaret Hamilton, astronaut, physicist and entrepreneur Sally Ride and astronaut, physician and engineer Mae Jemison&acirc;&#8364;&#8221;and 3 builds illustrating their areas of expertise. Role-play space exploration from planning to moon landing, beginning with the iconic scene from Massachusetts Institute of Technology in 1969 of Hamilton with software that she and her team programmed. Build the posable Hubble Space Telescope and launch a LEGO version of the Space Shuttle Challenger with 3 removable rocket stages. The set also includes a booklet about the 4 featured women of NASA, and the fan creator and LEGO designers of this fun and educational set.</span><div class="ProductFeatures__BulletText-s6my6ry-2 UbHkR"><span><ul><li> Includes 4 minifigures: Nancy Grace Roman, Margaret Hamilton, Sally Ride and Mae Jemison.
</li><li> Features 3 LEGO&Acirc;&reg; builds illustrating the areas of expertise of the 4 featured women of NASA.
</li><li> Nancy Grace Roman&acirc;&#8364;&#8482;s build features a posable Hubble Space Telescope with authentic details and a projected image of a planetary nebula.
</li><li> Margaret Hamilton's build features a stack of book elements, representing the books of listings of Apollo Guidance Computer (AGC) onboard flight software source code.
</li><li> Sally Ride and Mae Jemison&acirc;&#8364;&#8482;s build features a launchpad and Space Shuttle Challenger with 3 removable rocket stages.
</li><li> Also includes printed nameplates for each of the 4 women featured in this set.
</li><li> Great for role-playing space exploration missions.
</li><li> Includes a booklet with building instructions, plus information about the 4 featured women of NASA, the set's fan creator and the LEGO designers.
</li><li> Nancy Grace Roman's build measures over 2" (7cm) high, 3&acirc;&#8364; (9cm) wide and 2&acirc;&#8364; (6cm) deep.
</li><li> Margaret Hamilton&acirc;&#8364;&#8482;s build measures over 2" (6cm) high, 3&acirc;&#8364; (8cm) wide and 1&acirc;&#8364; (4cm) deep.
</li><li> Sally Ride and Mae Jemison&acirc;&#8364;&#8482;s build measures over 4" (12cm) high, 3&acirc;&#8364; (10cm) wide and 2&acirc;&#8364; (6cm) deep.</li></ul></span></div>

当内容显示在网站的前端时,实体无法正确显示。看起来是某种形式的UTF-8编码问题?

enter image description here

我查看了this UTF-8 debug tool website,发现错误的字符与我希望在表的左侧找到的字符匹配。

enter image description here

我尝试过:

  • 将utf8_decode()应用于post_content
  • 将htmlentities()应用于post_content
  • 从post_content删除wptexturize过滤器

这些都没有为我工作。我认为问题更复杂,可能与原始文本的字符编码有关吗?它来自基于Windows的系统的XML响应。这与Windows字符编码有关吗?

更新

对此问题的评论表明,此问题是在WordPress掌握之前发生的。我正在通过PHP中的cURL从基于Windows的API请求XML中的内容,然后使用simplexml_load_string对其进行解析。如果我将XML响应直接转储到文件,则编码正确。见下文。

<productSpecificationDetail><![CDATA[<span>Explore the professions of some of the groundbreaking women in science, technology, engineering and mathematics (STEM) with the LEGO® Ideas Women of NASA set. It features minifigures of 4 pioneering women of NASA— astronomer and educator Nancy Grace Roman, computer scientist and entrepreneur Margaret Hamilton, astronaut, physicist and entrepreneur Sally Ride and astronaut, physician and engineer Mae Jemison—and 3 builds illustrating their areas of expertise. Role-play space exploration from planning to moon landing, beginning with the iconic scene from Massachusetts Institute of Technology in 1969 of Hamilton with software that she and her team programmed. Build the posable Hubble Space Telescope and launch a LEGO version of the Space Shuttle Challenger with 3 removable rocket stages. The set also includes a booklet about the 4 featured women of NASA, and the fan creator and LEGO designers of this fun and educational set.</span>

cURL和SimpleXML之间的过程的哪一部分会以这种方式受到影响?我看不到在内容检索期间的任何地方都指定了特定的字符集。

0 个答案:

没有答案