Reading in Malformed XML (unencoded XML entities) with PHP

前端 未结 2 1242
难免孤独
难免孤独 2020-12-19 22:35

I\'m having some trouble parsing malformed XML in PHP. In particular I\'m querying a third party webservice that returns data in an XML format without encoding the XML enti

相关标签:
2条回答
  • 2020-12-19 23:14
    1. Read the content as a string.
    2. htmlspecialchars(preg_replace('/[\x-\x8\xb-\xc\xe-\x1f]/','',$string))
    3. Load the transformed string in SimpleXMLElement

    It worked for me so far.

    0 讨论(0)
  • 2020-12-19 23:21

    Try tidy.repairString:

    php > $tidy = new tidy();
    php > $repaired = $tidy->repairString("<foo>I <3 Philadelphia</foo>", array("input-xml"=>1));
    php > print($repaired);
    <foo>I &lt;3 Philadelphia</foo>
    php > $el = new SimpleXMLElement($repaired);
    
    0 讨论(0)
提交回复
热议问题