Jump to content


dynamic images

  • Please log in to reply
2 replies to this topic

#1 bluedogatdingdong

  • Members
  • PipPip
  • Member
  • 10 posts
  • LocationPenzance, Cornwall

Posted 25 February 2005 - 12:59 AM

I'm sure the code must be quite simple, but I can't find an example anywhere.

All I want to do is instead of displaying the image name eg boat.jpg actually display the image.

Any help much appreciated.


#2 DFWBounce

  • Members
  • Pip
  • Newbie
  • 1 posts

Posted 09 March 2005 - 09:19 AM

I'm not sure if you're asking how to display the image using php instead of html but if so... this is how to do it:
[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
[span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]echo ([/span][span style=\"color:#DD0000\"]\"<img src=\\"[/span][span style=\"color:#0000BB\"]boat[/span][span style=\"color:#007700\"].[/span][span style=\"color:#0000BB\"]jpg[/span][span style=\"color:#007700\"]&[/span][span style=\"color:#FF8000\"]#092;\">\");

[/span][span style=\"color:#0000BB\"]?>[/span]
You have to use the \ before the quotes in the html so that the server understands that they are not part of the php code. Hope this helps. (note: in the code above, the group of characters after "jpg" and before ">"); should actually be a forward slash "\".... I'm not sure why it wouldn't show up as a forward slash)

#3 jesserules

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 March 2005 - 03:05 AM

if you want to display an image depending on a var, do it like this:
[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]
[span style=\"color:#0000BB\"]<?php
$image [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"image.jpg\"[/span][span style=\"color:#007700\"];
echo [/span][span style=\"color:#DD0000\"]\"<img src=$image>\"[/span][span style=\"color:#007700\"];
[/span][span style=\"color:#0000BB\"]?>
the reason you do it like this is that PHP outputs in the form of HTML. in HTML typing in <img src=image.jpg> will include the image, so that's how you do it in PHP.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users