Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.