hoopplaya4 Posted November 23, 2008 Share Posted November 23, 2008 Hi All, I'm trying to write a PHP script to strip the embed code of a YouTube Video. For example, with a YouTube embed code like this: <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/5P6UU6m3cqk&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/5P6UU6m3cqk&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object> I'd like to strip it down to just this: 5P6UU6m3cqk I know that I would need to use "str_replace" or perhaps "strip_tags" but I'm not sure how to go about doing so. Any help would be very much appreciated! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 23, 2008 Share Posted November 23, 2008 So you want to get the video ID out? Try this: $str = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/5P6UU6m3cqk&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/5P6UU6m3cqk&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>'; preg_match("#http://www.youtube.com/v/([\d\w]+)&.*#i", $str, $match); echo $match[1]; Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted November 23, 2008 Author Share Posted November 23, 2008 Hey ProjectFear: Thanks for the reply. That worked out perfectly! I'm still pretty new to PHP, so I appreciate the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.