Posted By

claudiowebdesign on 08/27/11


Tagged

php html images files img


Versions (?)

Quick img tag


 / Published in: PHP
 

If you keep all image files to be displayed in a directory this could be a quicker and simplier way to write the proper tag

  1. <?php
  2.  
  3. function image($file){
  4. $alt = str_replace('-',' ',join(explode('.',$file,-1)));
  5. $dim = getimagesize('./layout/images/'.$file);
  6. echo '<img src="./layout/images/'.$file.'" alt="'.$alt.'" '.$dim[3].">\n";
  7. return;
  8. }
  9.  
  10. /*
  11.   EXAMPLE:
  12.   <?php image('my-hd-wallpaper.png'); ?>
  13.   PRODUCES:
  14.   <img src="./folder/my-hd-wallpaper.png" alt="my hd wallpaper" width="XXX" height="XXX">
  15. */
  16.  
  17. ?>

Report this snippet  

You need to login to post a comment.