Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 8, 2019 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/442ce682d5809676342ac6717adfceb8 to your computer and use it in GitHub Desktop.
Save parzibyte/442ce682d5809676342ac6717adfceb8 to your computer and use it in GitHub Desktop.
Convertir imagen normal a imagen AMP con PHP - https://parzibyte.me/blog/2018/08/29/expresion-regular-para-imagenes-amp/
<?php
$contenido = '<p>Soy un párrafo</p><img class="img-fluid" alt="Imagen" src="https://avatars0.githubusercontent.com/u/9124824?v=4">';
$contenidoAMP = preg_replace('/<img.*?src="([^"]*)".*?>/i', '<amp-img width="10" height="5" layout="responsive" src="$1"></amp-img>', $contenido);
echo $contenidoAMP;
#Imprime:
/*
<p>Soy un párrafo</p><amp-img width="10" height="5" layout="responsive" src="https://avatars0.githubusercontent.com/u/9124824?v=4"></amp-img>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment