How can I take the YouTube embedded code that YouTube provides and use a regular expression to convert it to valid FBML code, that is, use the fb:swf tag?
So far the regular expression I’ve come up with is:
preg_replace('/<object(.*)<\/object>/i', "Whatever I need here...", $str);
I know it’s lame, but it’s my first try.
PS: Sample of the YouTube embedded code,
<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/NWHfY_lvKIQ&hl=en_GB&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/NWHfY_lvKIQ&hl=en_GB&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>
As far as I’ve figured, you want to gather the video URL from the embedded code and then you do your thing and get whatever you want with it.
Assuming that there would only be two URLs in the whole embedded code (source and value) and that there are no quotes in URL’s (at least not YouTube’s) the regular expression I’d use to get the URL is:
Explanation:
httpthat isn’t precceeded by ‘src=”‘ is got until there is a quote.