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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?