By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Help - PHP Variables Used in HTML <IMG Tag

P: n/a
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="">';
?>

Jul 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sat, 02 Aug 2003 15:15:05 GMT, Ralph Freshour <ra***@primemail.com>
scrawled:
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="">';
?>


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=\"\" \/>";
?>

Jul 16 '05 #2

P: 2
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.
Apr 30 '06 #3

P: 2
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.
May 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.