Jump to content

get DOMNode as text


vannus

Recommended Posts

<domnode>inside part</domnode>

 

i can get the content of a node easily enough

echo $myDOMNode->nodeValue; outputs 'inside part'

echo $myDOMNode->textContent; outputs 'inside part'

echo $myDOMNode->get_content; outputs 'inside part'

 

how to i get the node itself as text/string?

ie. echo $myDOMNode->asText; would output '<domnode>inside part</domnode>'

 

is it even possible???

 

annoyingly even below hasnt worked for me :(

$doc=new DOMDocument();

$doc->appendChild($doc->importNode($myDOMNode,true));

echo $doc-saveHTML();

i had to import cause $myDOMNode is really an $xpath->query('//domnode')->item(0) result.

 

any help would be appreciated cause this is doing my head in!

 

Jim.

Link to comment
https://forums.phpfreaks.com/topic/163908-get-domnode-as-text/
Share on other sites

  • 2 weeks later...

 

annoyingly even below hasnt worked for me :(

$doc=new DOMDocument();

$doc->appendChild($doc->importNode($myDOMNode,true));

echo $doc-saveHTML();

i had to import cause $myDOMNode is really an $xpath->query('//domnode')->item(0) result.

 

 

just a typo...

 

$doc=new DOMDocument();

$doc->appendChild($doc->importNode($myDOMNode,true));

echo $doc->saveHTML();

 

although some form of DomNode->getNodeAsText(bool $deep) would be nice...

Link to comment
https://forums.phpfreaks.com/topic/163908-get-domnode-as-text/#findComment-871401
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.