views:

42

answers:

2

So I've got the following HTML code:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;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 :)

A: 

This would be a very basic but working regexp:

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

edit: Per comment below:

/<param\s+name="movie"\s+value="([^"]+.flv)"/i
poke
nice attempt but there may be multiple src's not all of which would be an object tag in the html.
CogitoErgoSum
+2  A: 

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  ...
Pekka