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

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条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog