开发者

preg_replace remove Youtube and Vimeo Object and Embed links

开发者 https://www.devze.com 2023-01-08 22:31 出处:网络
I\'m really new to regex-expressions, so I w开发者_JS百科as 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

I'm really new to regex-expressions, so I w开发者_JS百科as 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"><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"></param><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"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=123456&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="549" height="309" src="http://vimeo.com/moogaloop.swf?clip_id=123456&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object>


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

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

精彩评论

暂无评论...
验证码 换一张
取 消