note 126682 added to domdocument.createdocumentfragment

From: Date: Tue, 14 Dec 2021 19:37:18 +0000
Subject: note 126682 added to domdocument.createdocumentfragment
Groups: php.notes 
Request: Send a blank email to php-notes+get-217365@lists.php.net to get a copy of this message
You can use fragments to set inner HTML: <?php $dom = new DOMImplementation(); $document = $dom->createDocument(null, 'html', $dom->createDocumentType('html')); $div = $document->appendChild($document->createElement('div', '<small>test</small> me')); echo $document->saveHTML($div); // <div>&lt;small&gt;test&lt;/small&gt; me</div> $div = $document->appendChild($document->createElement('div')); $div->nodeValue = '<small>test</small> me'; echo $document->saveHTML($div); // <div>&lt;small&gt;test&lt;/small&gt; me</div> $div = $document->appendChild($document->createElement('div')); $divInner = $document->createDocumentFragment(); $divInner->appendXML('<small>test</small> me'); $div->appendChild($divInner); echo $document->saveHTML($div); // <div><small>test</small> me</div> ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 31.129.215.166) ---- Manual Page -- https://php.net/manual/en/domdocument.createdocumentfragment.php Edit -- https://main.php.net/note/edit/126682 Del: integrated -- https://main.php.net/note/delete/126682/integrated Del: useless -- https://main.php.net/note/delete/126682/useless Del: bad code -- https://main.php.net/note/delete/126682/bad+code Del: spam -- https://main.php.net/note/delete/126682/spam Del: non-english -- https://main.php.net/note/delete/126682/non-english Del: in docs -- https://main.php.net/note/delete/126682/in+docs Del: other reasons-- https://main.php.net/note/delete/126682 Reject -- https://main.php.net/note/reject/126682 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217365) next »