Skip to content

Instantly share code, notes, and snippets.

@netcarver
Created May 13, 2012 13:33
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 netcarver/58c953ad02a7d2192ba9 to your computer and use it in GitHub Desktop.
Save netcarver/58c953ad02a7d2192ba9 to your computer and use it in GitHub Desktop.
Youtube link changer
if(strpos($page->body, '<p>http://www.youtube.com') !== false) {
$replacement = '<iframe width="640" height="360" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>';
$page->body = preg_replace('#<p>\s*http://www.youtube.com/watch[/]?\?v=([^\s&<]+).*?</p>#iu', $replacement, $page->body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment