- libxml_use_internal_errors: documentation ( source)
<?php
$text = <<<'HTML'
<p>mon texte de début</p>
<pre>
<?php
# Pour afficher un tableau PHP
$var['website'] = 'domain.tld';
$var['weblink'] = 'http://www.domain.tld';
# BUG ICI
echo '<pre>'.print_r($var,1).'</pre>'
echo 'My domain : '.$var['website']
?>
</pre>
<p>mon texte de fin.</p>
HTML;
libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTML('<html><head><meta charset="UTF-8"/></head><body>' . $text . '</body></html>');
foreach($dom->getElementsByTagName('body')->item(0)->childNodes as $childNode) {
echo $dom->saveHTML($childNode);
}