开发者

Regex to replace FLV PLayer in PHP for CKEditor

So I've got the following HTML code:

<object cla开发者_Go百科ssid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="high" /><param name="movie" value="/uploads/flash/test1.flv" /><embed pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="/uploads/flash/test1.flv" type="application/x-shockwave-flash"></embed></object>

What I'm looking to do is extract the value of the param name movie i.e. strip it all and keep only the "uploads/flash/test1.flv" (Sans quotes). The HTML will be stored in a var. There may be multiple objects within the variable. I need ot replace them inline per say with a new object type.

For context on this problem, we are using CK editor which allows uploading of flsah files etc into a WYSIWYG editor. The problem is to play an FLV you need an FLV Player. We use Flowplayer right now, but to use it we'd need to replace CKEditors default FLV code. Rather than hack away at CKEditor we'd like to replace the code as it renders on the php side right before its sent to the user.

If anyone has CKEditor knowledge or an easier solution please feel free to throw them out there :)


Don't use a regular expression. Use a DOM parser like PHP's built in one.

$dom = new DOMDocument;
$dom->loadHTML(your HTML code here);
$allElements = $dom->getElementsByTagName('object');

foreach ($allElements as $element)
 // ... do something with each `object` tag  ...


This would be a very basic but working regexp:

/src="([^"]+.flv)"/i

edit: Per comment below:

/<param\s+name="movie"\s+value="([^"]+.flv)"/i
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜