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

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 05: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部