开发者

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/(.*?)&@';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜