Fix malformed XML in PHP before processing using DOMDocument functions

后端 未结 3 1367
抹茶落季
抹茶落季 2020-11-27 20:50

I\'m needing to load an XML document into PHP that comes from an external source. The XML does not declare it\'s encoding and contains illegal characters like &

3条回答
  •  没有蜡笔的小新
    2020-11-27 21:16

    To solve this issue, set the DomDocument recover property to TRUE before loading XML Document

    $dom->recover = TRUE;

    Try this code:

    $feedURL = '3704017_14022010_050004.xml';
    $dom = new DOMDocument();
    $dom->recover = TRUE;
    $dom->load($feedURL);
    

提交回复
热议问题