Regular expression with YouTube videos [solved] |
[eluser]codelearn[/eluser]
I wanted to throw out a question to you guys because I'm not much of a regular expression wizard. I have a YouTube video embed code which I need to validate before placing on my site: Code: <object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/5PsnxDQvQpw&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/5PsnxDQvQpw&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object> How do I use regular expression to just pull out the link (http://www.youtube.com/v/5PsnxDQvQpw&rel=1) from that code? Is this easily done? Thanks for any help. =) EDIT: A tiny bit of fiddling with the regular expression below did the trick. Thanks.
[eluser]Nick Husher[/eluser]
Something to the effect of /\w+src="(.+)"/ should do it. You have to figure out how to make that a nongreedy match, though, and I've forgotten how to do that.
[eluser]ejangi[/eluser]
I just very quickly threw this together and it seems to grab just the URL: Code: $string = '<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/5PsnxDQvQpw&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/5PsnxDQvQpw&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>'; You may want to check it on a few different movies though just to be sure. |
Welcome Guest, Not a member yet? Register Sign In |