Getting node's text in PHP DOM

前端 未结 2 561
无人共我
无人共我 2020-11-28 13:32

How could I extract the string \"text\" from this markup using the PHP DOM?

notthistext

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 13:51

    You can access DOMText node directly using XPath:

    $xpath = new DOMXPath($dom_document);
    $node = $xpath->query('//div/text()')->item(0);
    echo $node->textContent; // text
    

提交回复
热议问题