asked in PHP by (8.9k points) edited by
0 like 0 dislike
46 views

How give DOMElement as string in DOM?

Such methods do not work:

$sOutputData = $oDOMElement->saveXML();
$sOutputData = $oDOMElement->__toString();

1 Answer

0 like 0 dislike
answered by (8.9k points) edited by

Here is a universal function for this. The function takes a DOM element and returns it as a regular string.

function getStringFromDom($element) {
	$newdoc = new DOMDocument();
	$cloned = $element->cloneNode(true);
	$newdoc->appendChild($newdoc->importNode($cloned, true));
	return $newdoc->saveHTML();
}

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related questions

0 like 0 dislike
1 answer 3 views
0 like 0 dislike
1 answer 26 views
0 like 0 dislike
1 answer 29 views
0 like 0 dislike
1 answer 33 views
0 like 0 dislike
1 answer 53 views
0 like 0 dislike
1 answer 29 views
0 like 0 dislike
1 answer 41 views
0 like 0 dislike
1 answer 21 views
0 like 0 dislike
1 answer 12 views
...