Topic: Replacing <img> with <object>
I am in the process of modifying my PunBB installation to use <object> tags instead of <img> tags for more alternative content options and for future compatibility. I am almost finished making the changes and while I have encountered a few a problems in the process, only one problem (that I know of) remains:
The "type" attribute in the <object> tag contains the mime type for the media used in the object.
For example, this is how the PHP would output the HTML for the .png icon:
<object type="image/png" data="http://www.w3.org/Icons/valid-css.png" width="88" height="31">Valid CSS </object>
What I want the PHP to do is look for the data file (in this example, valid-css.png) and automatically fill in the mime type in the type attribute type="image/png"
Let's say that a forum user decided to embed a .gif image. How could I rewrite the following PHP (from ../include/parser.php) to automatically write type="image/gif" or write type="image/jpeg" for a .jpg?
Original:
if ($is_signature && $forum_user['show_img_sig'] != '0')
$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.forum_htmlencode($alt).'" />';
else if (!$is_signature && $forum_user['show_img'] != '0')
$img_tag = '<span class="postimg"><img src="'.$url.'" alt="'.forum_htmlencode($alt).'" /></span>';
My current modifications:
if ($is_signature && $forum_user['show_img_sig'] != '0')
$img_tag = '<object type="image/png" data="'.$url.'" class="sigimage">'.forum_htmlencode($alt).'</object>';
else if (!$is_signature && $forum_user['show_img'] != '0')
$img_tag = '<span class="postimg"><object type="image/png" data="'.$url.'">'.forum_htmlencode($alt).'</object></span>';