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! Link to comment https://forums.phpfreaks.com/topic/133843-solved-how-to-strip-tags-from-youtube-embed-code/ 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]; Link to comment https://forums.phpfreaks.com/topic/133843-solved-how-to-strip-tags-from-youtube-embed-code/#findComment-696609 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. Link to comment https://forums.phpfreaks.com/topic/133843-solved-how-to-strip-tags-from-youtube-embed-code/#findComment-696612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.