Help - PHP Variables Used in HTML <IMG Tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    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_photo 2_file" WIDTH="268" HEIGHT="176" BORDER="0"
    ALT="">';
    ?>

  • James

    #2
    Re: Help - PHP Variables Used in HTML &lt;IMG Tag

    On Sat, 02 Aug 2003 15:15:05 GMT, Ralph Freshour <ralph@primemai l.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_photo 2_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_fil e ?>" WIDTH="268"
    HEIGHT="176" BORDER="0" ALT="" />

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

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

    or

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

    Comment

    • RichardGUSA
      New Member
      • Apr 2006
      • 2

      #3
      Include PHP variable in &lt;img src=

      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.p hp?h1=110&h2=12 0&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.p hp?h1=$height1& h2=$height2&h3= height3">';

      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.

      Comment

      • RichardGUSA
        New Member
        • Apr 2006
        • 2

        #4
        Solved my own problem - found this on php.net I think

        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 . '">';

        Originally posted by RichardGUSA
        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.p hp?h1=110&h2=12 0&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.p hp?h1=$height1& h2=$height2&h3= height3">';

        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.

        Comment

        Working...