PHP HTML DomDocument getElementById problems

后端 未结 2 1419
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 07:40

A little new to PHP parsing here, but I can\'t seem to get PHP\'s DomDocument to return what is clearly an identifiable node. The HTML loaded will come from the \'net so ca

2条回答
  •  我在风中等你
    2020-11-27 07:47

    Well, you should check if $dom->loadHTML($html); returns true (success) and I would try

     var_dump($belement->nodeValue);
    

    for output to get a clue what might be wrong.

    EDIT: http://www.php-editors.com/php_manual/function.domdocument-get-element-by-id.html - it seems that DomDocument uses XPath internally.

    Example:

    $xpath = xpath_new_context($dom);
    var_dump(xpath_eval_expression($xpath, "//*[@ID = 'YOURIDGOESHERE']"));
    

提交回复
热议问题