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

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

  a
   b 

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

3条回答
  •  死守一世寂寞
    2021-01-06 04:37

    This might be helpful. Using what I found here and here

    $txt = "";
    foreach($foo->childNodes as $node) {
        if ($node->nodeType == XML_TEXT_NODE) {
            $txt .= $node->nodeValue;
        }
    }
    

提交回复
热议问题