开发者

extract YouTube URL from random text in PHP

Im trying to extract a YouTube link from just random text. e.g.

This is some random text and url is http://www.youtube.com/watch?v=-d3RYW0YoEk&feature=channel and I want to pull this URL out of this text in PHP. Can't seem to figure it out. Found a solution in ano开发者_开发百科ther language but don't know how to convert it. Thanks for the help.


You can use preg_match_all to grab all such URL's as:

if(preg_match_all('~(http://www\.youtube\.com/watch\?v=[%&=#\w-]*)~',$input,$m)){
 // matches found in $m
}


you could try to use Regex

http://php.net/manual/en/function.preg-match.php


Use preg_match.

The pattern should be something like:

/(http\:\/\/www\.youtube\.com\/watch\?v=\w{11})/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜