PHP – Make Youtube embed code from an Url

A small php function that transforms a youtube url in its embed script.

function make_youtube_embed_from_url($url)
{
$url = str_replace(‘?v=’,’/v/’,$url);
$out = ‘<object width=\”425″ height=\”350\”><param name=\”movie\” value=\”‘. $url .’\”></param><param name=\”wmode\” value=\”transparent\”></param><embed src=\”‘. $url .’\” type=\”application/x-shockwave-flash\” wmode=\”transparent\” width=\”425\” height=\”350\”></embed></object>’;
return $out;
}

Leave a Reply

Your email address will not be published. Required fields are marked *