I am writing temporary PHP script to update MySQL database of my vBulletin forum.
Here's what it does. It finds any entry that has a [youtube][/youtube] code. And then it has to replace that code with a link to the youtube video instead.
So, here is an example of what I have to take:
$string = <<<END
Hi everyone! Check out this video that I just found on YouTube!
[youtube]<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Md1E_Rg4MGQ&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Md1E_Rg4MGQ&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>[/youtube]
END;
And I have to make that look like this instead:
[URL=http://www.youtube.com/watch/?v=Md1E_Rg4MGQ]http://www.youtube.com/watch/?v=Md1E_Rg4MGQ[/URL]
I'm getting a headache working with the Regex. I don't have enough experience with Regex to figure out what to do.
It has to look something like this:
$string = preg_replace("#\[youtube\]?????\[/youtube\]#i", "[URL=http://www.youtube.com/watch?v=$1]http://www.youtube.com/watch?v=$1[/URL]", $string);
Help Please! ^_^