dsjlqkbpn029473708 2013-05-21 18:16
浏览 53
已采纳

PHP DOM DOCUMENT无法加载文件

All,

I am trying to load an XML file into DOM, but it fails due to the following reason:

  1. Presence of the registered trademark ® (R with Circle) in the file.

Basically, if it shows the trademark sign (R with a Circle) then DOM fails to load the file.

The Error that is displayed are:

encoder errorCData section not finished 
Premature end of data in tag elm line 12

When I check encoding of the file I get ASCII. If I physically remove that Character from the file, then everything works just fine.

I am loading the file using the following code:

$xml_dom = new DOMDocument();
$xml_dom->preserveWhiteSpace = false;
$result = $xml_dom->load($file);

$result = '' (empty) when it fails. But when I remove the trademark character and everything works, $result = 1

Is there a way to ask DOM to ignore that character? Is that character supposed to show if encoding is ASCII?. This file is not generated by me, so changing encoding at this point is not an option.... Thank you!

  • 写回答

2条回答 默认 最新

  • dtq26360 2013-06-13 06:42
    关注

    Try that method:

    $pageDom = new DomDocument();    
    $searchPage = mb_convert_encoding($htmlUTF8Page, 'HTML-ENTITIES', "UTF-8"); 
    @$pageDom->loadHTML($htmlUTF8Page);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?