For those who are good at regular expressions, I'd like to take the Youtube embed string that they supply and extract the video id. So for this string...
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/BDqs-OZWw9o&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/BDqs-OZWw9o&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
How can we use preg_replace to grab the id, which in this case is
BDqs-OZWw9o
Anyone know? Thanks.
The simplest thing I see is:
if(preg_match('#/([^/&]+)&rel=#', $string, $matches)) { $id = $matches[1]; } else { // not found }
Thanks for the suggestion. I tried the solution and it didn't quite work. It couldn't find a match for that expression. But now I know which direction to go. I'll have to look at this later. If I get it to work, I'll post what I did.