Last active
March 21, 2025 15:39
-
-
Save jsit/ca777a3ca71e725d9630 to your computer and use it in GitHub Desktop.
PHP preg_replace strings for AMP HTML extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$body = preg_replace( '/<iframe\b[^>]*width="([^"]*)"[^>]*height="([^"]*)"[^>]*youtube.com\/embed\/([^"]*)[^>]*>(.*?)>/', '<amp-youtube width="$1" height="$2" data-videoid="$3" layout="responsive"></amp-youtube>', $body ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment