eysikal Posted October 13, 2009 Share Posted October 13, 2009 First off, I am new and I apologize if I have not posted this in the correct forum. What I need to do is fairly simple, but I am not familiar enough with the string functions in PHP to do it. I am trying to: Parse out the URL from the embed code string that Youtube generates. Here is an example embed string: <object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object> I am trying to pull out only the "http://www.youtube.com...etc" from the "<param name="movie" tag. Can someone help me with this? I am unsure if this would best be done with regular expressions or with a PHP string function. Thanks. Link to comment https://forums.phpfreaks.com/topic/177605-need-help-parsing-out-url-from-youtube-embed-string/ Share on other sites More sharing options...
MadTechie Posted October 13, 2009 Share Posted October 13, 2009 try this <?php $html = '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/mzOWr3Fbtk0&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>'; if (preg_match('%<param .*?value="(http://www\.youtube\.com[^"]+)"%s', $html, $regs)) { $link = $regs[1]; echo $link; } ?> Link to comment https://forums.phpfreaks.com/topic/177605-need-help-parsing-out-url-from-youtube-embed-string/#findComment-936458 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.