开发者

I want to extract the video link out of youtube embed code, I am searching for a regex solution for this

For example: an youtube embed code

<object width="480" height="385">
        <param name="movie" value="http://www.youtube.com/v/TFlzeO267qY&hl=en_US&fs=1&"></param>
        <param name="allowFullScreen" value="true"></param>
        <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/TFlz开发者_如何转开发eO267qY&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
</object>

I want to extract http://www.youtube.com/v/TFlzeO267qY&hl=en_US&fs=1&" from this embed code but I dont know how to create a regex expression for this

Thanks in Advance?


I am not sure if this code is what you need .. try it and maybe it will help you to understand regex :

$var = '<object width="480" height="385">
        <param name="movie" value="http://www.youtube.com/v/TFlzeO267qY&hl=en_US&fs=1&"></param>
        <param name="allowFullScreen" value="true"></param>
        <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/TFlzeO267qY&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed>
</object>';
preg_match('/src="(.*?)"/', $var, $src);
$src = $src[1];
echo $src;


This should work for the example link you provided:

http://(?:www\.)?youtube\.com/v/[\w&=]+

You'll need to escape the slashes so that they are still part of the regex.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜