Get the text content of a node, but ignore child nodes

后端 未结 3 415
情话喂你
情话喂你 2021-01-06 04:35

  a
   b 

both $foo->textContent and $foo->nodeValue return a

3条回答
  •  忘掉有多难
    2021-01-06 04:46

    Try this code

    $doc = new DOMDocument();
    $doc->loadXML('abbar');
    $foos = $doc->getElementsByTagName('foo');
    foreach($foos as $v){
       echo $v->firstChild->wholeText.'
    '; }

    The firstChild property of DOMNode returns a DOMText object as there is a "text node" before in first

提交回复
热议问题