tags:

views:

60

answers:

2

For example: an youtube embed code

<object width="480" height="385">
        <param name="movie" value="http://www.youtube.com/v/TFlzeO267qY&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;
        <param name="allowFullScreen" value="true"></param>
        <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/TFlzeO267qY&amp;hl=en_US&amp;fs=1&amp;" 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&amp;hl=en_US&amp;fs=1&amp;" from this embed code but I dont know how to create a regex expression for this

Thanks in Advance?

+1  A: 

This should work for the example link you provided:

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

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

Senseful
I am new to regex, so can you please tell me the full syntax to retrieving out the link
Starx
+1  A: 

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&amp;hl=en_US&amp;fs=1&amp;"&gt;&lt;/param&gt;
        <param name="allowFullScreen" value="true"></param>
        <param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/TFlzeO267qY&amp;hl=en_US&amp;fs=1&amp;" 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;
bader