Search code examples
phpimagehtml-encode

display image using html_entity_decode


Currently I am trying to use html_entity_decode to display 2 images on the same page.

   $ent  = file_get_contents('./olympic.jpg');
   $ent1 = file_get_contents('./olympic1.jpg');
   $s  =  htmlspecialchars($ent1,ENT_COMPAT,'iso-8859-1');
   $s1 =  htmlspecialchars($ent,ENT_COMPAT,'iso-8859-1');

   $s2 = html_entity_decode($s, ENT_COMPAT,'iso-8859-1');
   $s3 = html_entity_decode($s1, ENT_COMPAT,'iso-8859-1');

   Header("Content-Type: image/jpeg");
   echo ($s2);
   echo ($s3);

I am now able to display $s2 but unable to display $s3. This is just a testing page, in the real system the image will be sent over from webservices in iso-8859-1 encoding. Any help would be appreciated.


Solution

  • This has nothing to do with html_entity_decode(). You can't display two images in a single HTTP response. You have to serve an HTML document (Content-Type: text/html) that contains two embedded images.