I want to get the
v=id from youtube's URL with javascript(no jquery, pure javascript);Example Youtube URL formats:
http://www.youtube.com/watch?v=u8nQa1cJyX8&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfWhttp://www.youtube.com/watch?v=u8nQa1cJyX8or any other youtube format what contains a
video id in the urlResult from these formats
u8nQa1cJyX8Solution:// Returns null if video id doesn't exist in URL
function get_video_id($url) {
$parts = parse_url($url);
// Make sure $url had a query string
if (!array_key_exists('query', $parts))
return null;
parse_str($parts['query']);
// Return the 'v' parameter if it existed
return isset($v) ? $v : null;
}http://stackoverflow.com/questions/4045154/grab-the-video-id-only-from-youtubes-urlshttp://snipplr.com/view/19232/

0 comments:
Post a Comment