damsean102
2/29/2016 - 5:21 PM

PHP preg_replace strings for AMP HTML extensions

PHP preg_replace strings for AMP HTML extensions

$body = preg_replace( '/<iframe\b[^>]*width="([^"]*)"[^>]*height="([^"]*)"[^>]*youtube.com\/embed\/([^"]*)[^>]*>(.*?)>/', '<amp-youtube width="$1" height="$2" data-videoid="$3" layout="responsive"></amp-youtube>', $body );
$body = preg_replace( '/<iframe\b[^>]*vimeo.com\/video\/(\d*).*"[^>]*width="([^"]*)"[^>]*height="([^"]*)"[^>]*[^>]*>(.*?)>/', '<amp vimeo layout="responsive" width="$2" height="$3" data-videoid="$1"></amp-vimeo>', $body );
$body = preg_replace( '/<blockquote class="twitter-tweet"[^>]*>.*\n*.*twitter.com\/\w*\/status\/(\d*)".*<\/blockquote>/', '<amp-twitter width=486 height=657 layout="responsive" data-tweetid="$1"></amp-twitter>', $body );
$body = preg_replace( '/<iframe\b[^>]*soundcloud.com\/tracks\/(\d*).*"[^>]*>(.*?)>/', '<amp-soundcloud height=300 layout="fixed-height" data-trackid="$1" data-visual="true"></amp-soundcloud>', $body );