function entity_embed_set_dom_node_content in Entity Embed 7
Same name and namespace in other branches
- 7.3 includes/entity_embed.html.inc \entity_embed_set_dom_node_content()
- 7.2 includes/entity_embed.html.inc \entity_embed_set_dom_node_content()
Set the contents of a DOMNode.
Parameters
\DOMNode $node: A DOMNode or DOMElement object.
string $content: The text or HTML that will replace the contents of $node.
File
- includes/
entity_embed.html.inc, line 151 - DOM processing functions.
Code
function entity_embed_set_dom_node_content(\DOMNode $node, $content) {
// Remove all children of the DOMNode.
while ($node
->hasChildNodes()) {
$node
->removeChild($node->firstChild);
}
if (strlen($content)) {
// Load the contents into a new DOMDocument and retrieve the elements.
$replacement_nodes = entity_embed_dom_load_html($content)
->getElementsByTagName('body')
->item(0);
// Finally, import and append the contents to the original node.
foreach ($replacement_nodes->childNodes as $replacement_node) {
$replacement_node = $node->ownerDocument
->importNode($replacement_node, TRUE);
$node
->appendchild($replacement_node);
}
}
}