Echo <object><embed> in php tags

Hi people,

I’m working on a script and having a problem parsing the above mentioned tags from a php variable (from DB) into plain html. All that I get is displaying the object code as text and not the movie it self.

If I copy the code into html tags it works but as soon as I try <?=$code;?> all i get is the code displayed instead of parsed. I have tried just about everything: htmlspecialchars, reversed special chars bla bla bla every available option from php.net tried without results.

There has to be a way to do it, I just have not had any luck finding it, trust me I’ve searched endlessly.

Thx for the help in advance.

Hi n2irock!
Welcome to the sitepoint forums.

Why not storing only the src value (flash filename) in the database and get rest of the HTML static in the page?


$filename = "flashfilename.swf";


<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="120">
  <param name="movie" value="<?php echo $filename;?>">
  <param name="quality" value="high">
  <embed src="<?php echo $filename;?>" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="120"></embed>
</object>

Rajug

I thought about that, however, I’m working on a script where people can post anything from for sale to personal posts and would like to have the ability to have them post embed’s from i.e. youtube. Get my drift?

Ah man… nevermind lol I found an error in my other code… it is late I need to go to sleep lol I figured it out. I forgot to decode the code BEFORE the statement… oh man… anyway thanks for your input.

I hope you have already used the function html_entity_decode() too, right? So try out like this if you have not already.


$str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="150" height="120">
  <param name="movie" value="login.swf">
  <param name="quality" value="high">
  <embed src="login.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="150" height="120"></embed>
</object>';
$str = htmlentities($str);
echo html_entity_decode($str, ENT_QUOTES);

Even better would be to replace that <embed> tag with real HTML. A second <object> tag is the right way to embed objects since there is no such html as <EMBED>.