Connect with Expertise | Find Experts, Get Answers, Share Insights

Help - PHP Variables Used in HTML <IMG Tag

Ralph Freshour
 
Posts: n/a
#1: Jul 16 '05
I'm trying to dynamically load a .jpg image into a html form <Img tag
using a PHP variable that holds the filename of the image but no image
is displaying (the file is there and works because if I manually type
in the filename the <Img tag works) - how can I get PHP's variable to
be seen as the filename?

Thanks...

<?php
print '<IMG SRC="$php_photo2_file" WIDTH="268" HEIGHT="176" BORDER="0"
ALT="">';
?>


James
 
Posts: n/a
#2: Jul 16 '05

re: Help - PHP Variables Used in HTML <IMG Tag


On Sat, 02 Aug 2003 15:15:05 GMT, Ralph Freshour <ralph@primemail.com>
scrawled:
[color=blue]
>I'm trying to dynamically load a .jpg image into a html form <Img tag
>using a PHP variable that holds the filename of the image but no image
>is displaying (the file is there and works because if I manually type
>in the filename the <Img tag works) - how can I get PHP's variable to
>be seen as the filename?
>
>Thanks...
>
><?php
>print '<IMG SRC="$php_photo2_file" WIDTH="268" HEIGHT="176" BORDER="0"
>ALT="">';
>?>[/color]

RTFM,

You are using "single quotes" which don't get expanded, only "double
quotes" have their content interpolated.

Why not...

<IMG SRC="<?php echo $php_photo2_file ?>" WIDTH="268"
HEIGHT="176" BORDER="0" ALT="" />

much simpler and easier to understand..., if not you can could do...

<?php
echo '<IMG SRC="',$php_photo2_file,
'" WIDTH="268" HEIGHT="176" BORDER="0" ALT="" />;
?>

or

<?php
echo "<IMG SRC=\"$php_photo2_file\" WIDTH=\"268\" HEIGHT=\"176\"
BORDER=\"0\" ALT=\"\" \/>";
?>

 
Join Date: Apr 2006
Posts: 2
#3: Apr 30 '06

re: Help - PHP Variables Used in HTML <IMG Tag


I am having a very similar problem to this post and have tried the suggestions given but still cannot do what I need to do. I have a PHP script that dynamically generates an image file (using JPGRAPH) and this works fine. I load this php file and pass data to it to create the image which is a graph using the following:

Print '<img src="barchart.php?h1=110&h2=120&h3=130">';

This correctly passes the three values to barchart.php and generates a graph image based on the three values. The problem is I want to pass different values to this php file every time I use the image so that it generates a different graph based on the values passed. The values are stored in php variables ($height1, $height2 and $height3) and I have been trying many different combinations of the following non of which work:

Print '<img src="barchart.php?h1=$height1&h2=$height2&h3=heigh t3">';

Does anyone know how I can correctly pass values stored in PHP variables to a HTML tag that I also happenning to be gererating within a PHP script. If someone can sugest a better way to pass variable values to barchart.php please let me know.
 
Join Date: Apr 2006
Posts: 2
#4: May 3 '06

re: Help - PHP Variables Used in HTML <IMG Tag


I have found a correct syntax for this to work on php.net I think. See below:

Print '<img src="barchart_a.php?h1=' . $height1 . '&h2=' . $height2 . '&h3=' . $height3 . '">';

I am having a very similar problem to this post and have tried the suggestions given but still cannot do what I need to do. I have a PHP script that dynamically generates an image file (using JPGRAPH) and this works fine. I load this php file and pass data to it to create the image which is a graph using the following:

Print '<img src="barchart.php?h1=110&h2=120&h3=130">';

This correctly passes the three values to barchart.php and generates a graph image based on the three values. The problem is I want to pass different values to this php file every time I use the image so that it generates a different graph based on the values passed. The values are stored in php variables ($height1, $height2 and $height3) and I have been trying many different combinations of the following non of which work:

Print '<img src="barchart.php?h1=$height1&h2=$height2&h3=heigh t3">';

Does anyone know how I can correctly pass values stored in PHP variables to a HTML tag that I also happenning to be gererating within a PHP script. If someone can sugest a better way to pass variable values to barchart.php please let me know.
Closed Thread

Tags
, img php, php img