3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Limpiar comentarios en una cadena HTML con PHP // https://es.stackoverflow.com/q/114030/127 $cadenaHTML = "codigo <b>util</b> <!-- codigo basura --> mas codigo util <!-- mas codigo basura -->"; //Englobamos en body porque tu ejemplo no tiene //para corregirlo y que lo procese bien $html = '<body>' . $cadenaHTML . '</body>'; //Generar el DOM $dom = new DOMDocument; $dom->loadHTML($html, LIBXML_COMPACT | LIBXML_HTML_NOIMPLIED | LIBXML_NONET | LIBXML_HTML_NODEFDTD); //Buscar cada comentario $xpath = new DOMXPath($dom); foreach ($xpath->query('//comment()') as $comment) { //eliminarlo $comment->parentNode->removeChild($comment); } //Guardar el html $resultado = $dom->saveHTML(); //Imprimir el resultado echo $resultado;
Output for git.master, git.master_jit, rfc.property-hooks
<body>codigo <b>util</b> mas codigo util </body>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
170.49 ms | 405 KiB | 5 Q