note 124522 added to domdocument.getelementsbytagname
| From: | MateuszK@php.net | Date: | Thu, 19 Dec 2019 08:04:54 +0000 |
| Subject: | note 124522 added to domdocument.getelementsbytagname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213555@lists.php.net to get a copy of this message | ||
If you want to move all nodes to another tag you can do it like that
Eg: replace <div> with nodes to <p> with the same nodes.
function replaceDomElementTag(DOMDocument $dom, DOMElement $node, string $tagName)
{
$newElement = $dom->createElement($tagName);
while ($node->childNodes->length)
$newElement->appendChild($node->childNodes[0]);
$node->parentNode->replaceChild($newElement, $node);
}
$dom = new DOMDocument();
replaceDomElementTag($dom, $divElementToReplace, 'p');
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.168 (proxied: 185.30.125.251)
----
Manual Page -- http://php.net/manual/en/domdocument.getelementsbytagname.php
Edit -- https://master.php.net/note/edit/124522
Del: integrated -- https://master.php.net/note/delete/124522/integrated
Del: useless -- https://master.php.net/note/delete/124522/useless
Del: bad code -- https://master.php.net/note/delete/124522/bad+code
Del: spam -- https://master.php.net/note/delete/124522/spam
Del: non-english -- https://master.php.net/note/delete/124522/non-english
Del: in docs -- https://master.php.net/note/delete/124522/in+docs
Del: other reasons-- https://master.php.net/note/delete/124522
Reject -- https://master.php.net/note/reject/124522
Search -- https://master.php.net/manage/user-notes.php