Created
March 26, 2013 21:18
-
-
Save phpfiddle/5249347 to your computer and use it in GitHub Desktop.
PHP DOM Sample.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function innerHTML($el) { | |
$doc = new DOMDocument(); | |
$doc->appendChild($doc->importNode($el, TRUE)); | |
$html = trim($doc->saveHTML()); | |
$tag = $el->nodeName; | |
return preg_replace('@^<' . $tag . '[^>]*>|</' . $tag . '>$@', '', $html); | |
} | |
$doc = new DOMDocument(); | |
// A corrupt HTML string | |
$doc->loadHTML('<HTML><A HREF="ss">asd</A>'); | |
$body = $doc->getElementsByTagName('body')->item(0); | |
print htmlspecialchars(innerHTML($body)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment