$node = $dom->getElementsByTagName('p')->item(0); $text = $node->textContent;
element in the document, and then use the textContent property of the DOMNode object to get the text contents of the node.
2. Updating the attributes of a node:
$node = $dom->getElementById('myElement'); $node->setAttribute('class', 'selected');
$node = $dom->getElementsByTagName('img')->item(0); $node->parentNode->removeChild($node);In this example, we use the getElementsByTagName() method to retrieve the first element in the document, and then use the removeChild() method of its parent node to completely remove the element from the document. The PHP DOMNode class is part of the PHP Standard Library, which means that it is included with every installation of PHP by default.