3v4l.org

run code in 300+ PHP versions simultaneously
<?php // eliminar esta etiqueta usando expresiones regulares php // https://es.stackoverflow.com/q/131277/127 $html = ' <p><figure><img src="xxxx"></figure></p> <p> <figure> <img src="2222"> </figure> </p>'; //Generar el DOM $dom = new DOMDocument; $libxml_opciones = LIBXML_COMPACT | LIBXML_HTML_NODEFDTD | LIBXML_NONET | LIBXML_NOERROR; @$dom->loadHTML($html, $libxml_opciones); //Generar un XPath para búsquedas $xpath = new DOMXpath($dom); //Obtener todos los tags <p> $p_nodelist = $dom->getElementsByTagName('p'); //Bucle para cada <p> (en orden inverso para preservar la estructura) for ($i = $p_nodelist->length; --$i >= 0; ) { $p = $p_nodelist->item($i); $p_hijos = $xpath->query('./*',$p); //Si el <p> tiene un único hijo, y ese hijo es un <figure> if ($p_hijos->length == 1 && $p_hijos->item(0)->tagName == 'figure') { $figure = $p_hijos->item(0); //Si el <figure> tiene un único hijo, y ese hijo es una <img> $figure_hijos = $xpath->query('./*',$figure); if ($figure_hijos->length == 1 && $figure_hijos->item(0)->tagName == 'img') { //REEMPLAZAR todo el <p> por solamente el <figure> $p->parentNode->replaceChild($figure,$p); } } } //Guardar el html $resultado = ''; foreach ($dom->documentElement->lastChild->childNodes as $elem) { $resultado .= $dom->saveHTML($elem); } //Imprimir el resultado echo $resultado;
Output for git.master, git.master_jit, rfc.property-hooks
<figure><img src="xxxx"></figure> <figure> <img src="2222"> </figure>

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:
67.97 ms | 401 KiB | 8 Q