fork(3) download
  1. <?php
  2. $body1='<iframe allowfullscreen="" class="giphy-embed" frameborder="0" height="480px" src="//giphy.com/embed/ul6oSSodZpDkA" width="480px"></iframe><iframe allowfullscreen="" class="giphy-embed" frameborder="0" height="270px" src="//giphy.com/embed/9GePVO7Lq9RVC" width="480px"></iframe><iframe allowfullscreen="" class="giphy-embed" frameborder="0" height="293px" src="//giphy.com/embed/iCxjRASxBW4cE" width="480px"></iframe><iframe allowfullscreen="" class="giphy-embed" frameborder="0" height="268px" src="//giphy.com/embed/gYCtjNPq3U6mA" width="480px"></iframe>';
  3. // your code goes here //Convertir utf8 a ISO-8859-1
  4. $htmlISO = mb_convert_encoding($body1, 'ISO-8859-1');
  5. //Generar el DOM
  6. $doc = new DOMDocument;
  7. $opcionesLibXML = LIBXML_COMPACT | LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD;
  8. $doc->loadHTML($htmlISO, $opcionesLibXML);
  9. //Obtener todos los iframes
  10. $iframes = $doc->getElementsByTagName('iframe');
  11. //Reemplazar c/u
  12. foreach ($iframes as $iframeViejo) {
  13. //Crear un nuevo iframe y asignar el src
  14. $iframeNuevo = $doc->createElement('img');
  15. $iframeNuevo->setAttribute('src', $iframeViejo->getAttribute('src'));
  16. //Crear un nuevo figure y agregarle el nuevo iframe
  17. $figureNuevo = $doc->createElement('figure');
  18. $figureNuevo->appendChild($iframeNuevo);
  19. //reemplazar viejo por nuevo
  20. $iframeViejo->parentNode->replaceChild($figureNuevo, $iframeViejo);
  21. }
  22. //DOM -> string final
  23. $body1 = $doc->saveHTML($doc->documentElement);
  24. echo $body1;
Success #stdin #stdout 0.02s 52488KB
stdin
Standard input is empty
stdout
<figure><img src="//giphy.com/embed/ul6oSSodZpDkA"></figure>