Skip to content

Instantly share code, notes, and snippets.

@blar
Created September 30, 2012 20:58
Show Gist options
  • Select an option

  • Save blar/3808435 to your computer and use it in GitHub Desktop.

Select an option

Save blar/3808435 to your computer and use it in GitHub Desktop.
<?php
$p = $document->createElement('p', 'foobar');
$elements = $document->getElementsByTagName('p');
$lastElement = $elements[$elements->length - 1];
if($lastElement->nextSibling) {
$elements->insertBefore($p, $lastElement->nextSibling);
}
else {
$lastElement->parentNode->appendChild($p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment