php preg_match and pattern
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 pa开发者_运维百科ttern: $pattern = '@^([^/v/]+)?([^=]+)@i';
But why result is: "youtube.com/v/NRH2jEyiiLo"?
How drop "youtube.com/v/", thanks ;)
$pattern = '@^([^/v/]+)?([^=]+)@i';
using this pattern then
$str= "youtube.com/v/NRH2jEyiiLo";
$newarr = explode('/',$str);
echo $newarr[2];
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
You shouldn't use a character class there, nor the start anchor.
$pattern = '@/v/(.*?)&@';
精彩评论