XML parser error: entity not defined

前端 未结 6 1840
醉话见心
醉话见心 2020-12-03 02:34

I have searched stackoverflow on this problem and did find a few topics, but I feel like there isn\'t really a solid answer for me on this.

I have a form that users

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 03:19

    I agree that it is purely an encoding issue. In PHP, this is how I solved this problem:

    1. Before passing the html-fragment to SimpleXMLElement constructor I decoded it by using html_entity_decode.

    2. Then further encoded it using utf8_encode().

    $headerDoc = '' . utf8_encode(html_entity_decode($headerFragment)) . ''; 
    $xmlHeader = new SimpleXMLElement($headerDoc);
    

    Now the above code does not throw any undefined entity errors.

提交回复
热议问题