Skip to content

Instantly share code, notes, and snippets.

@komlenic
Created November 17, 2011 18:54
Show Gist options
  • Save komlenic/1374083 to your computer and use it in GitHub Desktop.
Save komlenic/1374083 to your computer and use it in GitHub Desktop.
Get innerHTML of a php DOMElement
<?php
// See http://www.php.net/manual/en/class.domelement.php#101243
function get_inner_html( $node ) {
$innerHTML= '';
$children = $node->childNodes;
foreach ($children as $child) {
$innerHTML .= $child->ownerDocument->saveXML( $child );
}
return $innerHTML;
}
?>
@aravindan-tnq
Copy link

Awesome!

@hsa599
Copy link

hsa599 commented May 28, 2021

Thank's

@Sourabh-Semalty
Copy link

Hi, it's good and working but if there is any ol tag then it is being removed from there

@br4nnigan
Copy link

br4nnigan commented Oct 26, 2022

classic php, keeping it awkward. thanks for this

e: use saveHTML. saveXML will produce things like <div/>

@DingLipeng
Copy link

Thank you all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment