Reputation: 3823
i have url: youtube.com/v/NRH2jEyiiLo&hl=en&fs=1&rel=0
And i need only code: NRH2jEyiiLo&hl.
preg_match($pattern, $url, $matches);
I use this pattern: $pattern = '@^([^/v/]+)?([^=]+)@i';
But why result is: "youtube.com/v/NRH2jEyiiLo"?
How drop "youtube.com/v/", thanks ;)
Upvotes: 0
Views: 344
Reputation: 19380
Here's mine... (updated)
$url = "youtube.com/v/NRH2jEyiiLo&hl=en&fs=1&rel=0";
preg_match("#[A-Za-z0-9\-\_]{11}#", $url, $video);
echo($video[0]); //NRH2jEyiiLo
If you want to embed videos in your webpage, you can try this function... http://webarto.com/57/php-youtube-embed-function
Upvotes: 1
Reputation: 3634
$pattern = '@^([^/v/]+)?([^=]+)@i';
using this pattern then
$str= "youtube.com/v/NRH2jEyiiLo";
$newarr = explode('/',$str);
echo $newarr[2];
Upvotes: 1
Reputation: 838256
You shouldn't use a character class there, nor the start anchor.
$pattern = '@/v/(.*?)&@';
Upvotes: 0