473,499 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help - PHP Variables Used in HTML <IMG Tag

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
3 79121
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
RichardGUSA
2 New Member
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
RichardGUSA
2 New Member
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
13045
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in -...
5
2588
by: Sorby | last post by:
Hi I've been coding in PHP for a little while now and was starting to feel pretty confident but then realise I need to understand regular expressions to solve a particular problem I've got ......
8
2992
by: Eric Bragas | last post by:
What is this? <img src="{$ ImagesDir}/photo.gif"> I KNOW what an HTML image tag looks like. But what do you call that in the file source? Is it like a virtual directory in IIS? It's some type...
15
3069
by: Philipp Lenssen | last post by:
My friend has the following problem (background: we want to transform XML to XHTML via XSLT): "We copy XHTML fragments into an output by using the following template: <xsl:template match="*"...
15
122072
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
3
5423
by: Henry Johnson | last post by:
Okay - I'm spinning my wheels on this one... can someone help me figure out how to programmatically populate a table cell as follows (from C# code-behind)? I've tried using a Literal control in the...
7
9847
by: Christian Hackl | last post by:
Hi everyone, I've got a question about what makes the "img" element's width/height attributes valid HTML or XHTML. First of all, this is a rather theoretical question, but digging through the...
0
7128
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7006
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7385
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5467
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1425
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
294
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.