Reputation: 20223
I have a paragraph:
<p>
This is a test <xref>1</xref> in the XML <xref>2</xref> bla bla bla....
</p>
I would like to insert ]
after the xref
node.
For that, I am using the following code:
$refs = $paragraph->getElementsByTagName("xref");
foreach ($refs as $key=>$ref) {
$squareBracket = $dom_input->createTextNode("]");
$paragraph->appendChild($squareBracket);
}
But this is adding the ]
at the end of the paragraph.
Is there any function as insertBefore
but to insert after?
Upvotes: 0
Views: 128
Reputation: 20223
I found how to do it:
$squareBracket = $dom_input->createTextNode("]");
$paragraph->insertBefore($squareBracket, $ref->nextSibling);
We have to use nextSibling on the selected node.
Upvotes: 2