Skip to content

Instantly share code, notes, and snippets.

@brandonkramer
Last active April 12, 2022 23:58
Show Gist options
  • Save brandonkramer/b2f3dcf07747d2147c2d8b55fd07bcea to your computer and use it in GitHub Desktop.
Save brandonkramer/b2f3dcf07747d2147c2d8b55fd07bcea to your computer and use it in GitHub Desktop.
Get all (preg_match_all) Google docs embed iframes and wrap it with a div with PHP
<?php
preg_match_all( '@<iframe[^>]+?src="((?:https?:)?//(?:docs\.)?google\.com/([^"\'/]++)[^"\']*?)"[^>]*+>.*</iframe>@iUs', $content, $matches );
if ( isset( $matches[0] ) && isset( $matches[0][0] ) ) {
foreach ( $matches[0] as $googleDocIframe ) {
$content = str_replace( $googleDocIframe, '<div class="google-doc-iframe">' . $googleDocIframe . '</div>', $content );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment