Skip to content

Instantly share code, notes, and snippets.

@tonykwon
Created December 4, 2013 16:23
Show Gist options
  • Save tonykwon/7790503 to your computer and use it in GitHub Desktop.
Save tonykwon/7790503 to your computer and use it in GitHub Desktop.
Extracting iframes from html content
<?php
// $buffer contains the HTML generated
$extracted = array();
$pattern = "#<iframe[^>]+>.*?</iframe>#is";
preg_match_all($pattern, $buffer, $matches);
if ( $matches ) {
foreach($matches as $match) {
$buffer = strtr($buffer, array($match[0] => ''));
$extracted[] = $match[0];
}
}
if ( $extracted ) {
// we have iframe snippets from the html buffer
// do something with these
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment