duansao20000508 2017-10-30 13:13
浏览 84
已采纳

PHP DOMDocument对象具有null documentElement,用于有效的XML

The XML I'm working with is actually the RSS feed located at http://www.gjc.org/cgi-bin/rssjobs.pl

It seems to validate via the W3C RSS Feed and XML validators. When I do the following, I just get null.

$dom = new DOMDocument($xml);
$dom->loadXML($xml);
var_dump($dom->documentElement);

Am I missing something obvious? Maybe an encoding problem? Any insight would be appreciated.

  • 写回答

1条回答 默认 最新

  • duanhuang7591 2017-10-30 13:58
    关注

    You need to convert the encoding to make it work, try the following:

    $xml = file_get_contents("http://www.gjc.org/cgi-bin/rssjobs.pl");
    $xml = mb_convert_encoding($xml, 'HTML-ENTITIES', "UTF-8");
    
    $dom = new DOMDocument($xml);
    $dom->loadXML($xml);
    var_dump($dom->documentElement);
    

    This will convert the characters accordingly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探