\n\n"; print getVideoEmbedHtml('http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=2680075'); print "\n\n

\n\n"; print getVideoEmbedHtml('http://video.google.com/videoplay?docid=-3830684889540805606#'); print "\n\n

\n\n"; print getVideoEmbedHtml('http://vimeo.com/274366'); print "\n\n

\n\n"; print getVideoEmbedHtml('http://video.yahoo.com/watch/3015021/v2156453'); print "\n\n

\n\n"; print getVideoEmbedHtml('http://www.flickr.com/photos/roxandabear/3314163231/'); print "\n\n

\n\n"; print getAudioEmbedHtml('http://soundcloud.com/superape/ape-shit'); // TEST DATA END function getVideoEmbedHtml($videourl, $service = "auto", $width = 400, $height = 300) { $service = strtolower($service); $embedcode = ""; if ($service == "auto") { if (preg_match('/^http\:\/\/www\.youtube\.com/', $videourl) || preg_match('/^http\:\/\/youtu.be\//', $videourl)) $service = "youtube"; elseif (preg_match('/^http\:\/\/vids\.myspace\.com/', $videourl)) $service = "myspace"; elseif (preg_match('/^http\:\/\/video\.google\.com/', $videourl)) $service = "google"; elseif (preg_match('/^http\:\/\/vimeo\.com/', $videourl)) $service = "vimeo"; elseif (preg_match('/^http\:\/\/video\.yahoo\.com/', $videourl)) $service = "yahoo"; elseif (preg_match('/^http\:\/\/www\.flickr\.com/', $videourl)) $service = "flickr"; } switch ($service) { case "youtube": // Get the video ID from the video URL if (preg_match('/v=([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; elseif (preg_match('/^http\:\/\/youtu.be\/([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; else return false; // Make the embed code $embedcode .= ''; $embedcode .= ''; $embedcode .= ''; return $embedcode; case "myspace": // Get the video ID from the video URL if (preg_match('/videoid=([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; else return false; // Make the embed code $embedcode .= ''; $embedcode .= ''; $embedcode .= ''; $embedcode .= ''; $embedcode .= ''; $embedcode .= ''; return $embedcode; case "google": // Get the video ID from the video URL if (preg_match('/docid=([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; else return false; // Make the embed code $embedcode .= ' '; return $embedcode; case "vimeo": // Get the video ID from the video URL if (preg_match('/^http\:\/\/vimeo.com\/([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; else return false; // Make the embed code $embedcode .= ''; return $embedcode; case "yahoo": // Get the video ID from the video URL if (preg_match('/^http\:\/\/video.yahoo.com\/watch\/([0-9a-zA-Z-_]*)\/([0-9a-zA-Z-_]*)/', $videourl, $matches)) { $videoid1 = $matches[1]; $videoid2 = $matches[2]; } else return false; // Make the embed code $embedcode .= ''; $embedcode .= ''; return $embedcode; case "flickr": // Get the video ID from the video URL if (preg_match('/photos\/[0-9a-zA-Z-_]*\/([0-9a-zA-Z-_]*)/', $videourl, $matches)) $videoid = $matches[1]; else return false; // Make the embed code $embedcode .= ' '; $embedcode .= ''; return $embedcode; } } function getAudioEmbedHtml($videourl, $service = "auto", $width = 400) { if ($service == "auto") { if (preg_match('/^http\:\/\/soundcloud.com/', $videourl)) $service = "soundcloud"; } switch ($service) { case "soundcloud": if (!preg_match('/^http\:\/\/soundcloud.com\/.*/', $videourl)) return false; // Make the embed code $embedcode .= ' '; $embedcode .= ' '; return $embedcode; } } ?>