Possible Duplicate:
parse youtube video id using preg_match
$message = "this is an youtube video http://www.youtube.com/watch?v=w6yF_UV1n1o&feature=fvst i want only the id";
$message = preg_replace('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', '\\1', $message);
print $message;
the above prints…
this is an youtube video http://www.w6yF_UV1n1o&feature=fvst i want only the id
what i want is:
this is an youtube video w6yF_UV1n1o i want only the id
thanks in advance 🙂
First you would match a valid URL, then extract a valid YouTube ID from that URL, then replace the original URL found with the matching ID (if a valid ID was found):
Source: http://daringfireball.net/2009/11/liberal_regex_for_matching_urls & https://stackoverflow.com/a/6382259/1748964