views:

151

answers:

1

Hey!

I'm really new to regex-expressions, so I was wondering if someone would bother to come up with one or more regular-expressions for removing Youtube and Vimeo object url's. It doesen't really matter that it only removes Youtube-objects/embeds, as long as it removes the <object> and </object> and everything in between.

Thank you so much! :)

Example embeds:

<object classid="clsid:abc123_def456_ghi_789" width="560" height="340" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/abcdefg123456" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="560" height="340" src="http://www.youtube.com/v/abcdefg123456" allowscriptaccess="always" allowfullscreen="true"></embed></object>

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/abcdefeg12"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/abcdefeg12" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

<object classid="clsid:1234bcac" width="549" height="309" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=123456&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=1&amp;amp;color=00ADEF&amp;amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="549" height="309" src="http://vimeo.com/moogaloop.swf?clip_id=123456&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=1&amp;amp;color=00ADEF&amp;amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object>
+2  A: 

You can use preg_replace() with a pattern like this:

$content = preg_replace('%<object.+?</object>%is', '', $content);
WoLpH