Skip to content

Instantly share code, notes, and snippets.

@somatonic
Created April 23, 2012 11:09
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 somatonic/2470246 to your computer and use it in GitHub Desktop.
Save somatonic/2470246 to your computer and use it in GitHub Desktop.
Replace Youtube URLS with iframe
// replace youtube urls
if(strpos($page->body, '<p>http://www.youtube.com') !== false) {
$replacement = '<iframe width="444" height="280" src="http://www.youtube.com/embed/$1?$2" frameborder="0" allowfullscreen></iframe>';
$page->body = preg_replace('#<p>\s*http://www.youtube.com/watch\?v=([^\s&<]+)([\&amp\;+?].+).*?</p>#iu', $replacement, $page->body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment