Jump to content

Images as variables.


lamboman

Recommended Posts

I am Pretty new to PHP and I know this is something I have wrong with the way it is laid out. Any help would be appriciated.

I will be adding more images later (an array) but this is the start but it wont display the image

 

<?php

$bottle[0]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkblue.gif'">';

$bottle[1]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif'">';

  echo $bottle[0];

?>

 

Thanks in advance

Link to comment
Share on other sites

1. does the image exist on the server / your pc.

2. is the images folder sitting in the same directory as this test script.

3. you could try and see if the file exists:

 if (file_exists("images/bottlesandcaps/diamondbottles/smalldiamonddarkblue.gif")) {
        echo"image exists!";
    } else {
        echo"image does not exist!";
    }

 

Link to comment
Share on other sites

just before we get crap loads of if's

 

your syntax is wrong

 

$bottle[1]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif'">';

should be

$bottle[1]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif">';

 

in other words, the last part of your string has a ' to many  (should be ">';  and not '">'; )

 

besides that you are indeed missing an alt= " "  attribute as said above, but that was not breaking your syntax.

 

P.s. a small hint, count the " and ' they should be even numbers (they come in pairs ;) )

Link to comment
Share on other sites

You've not escaped the quotes in your strings? And there was an extra quote in the first string.

try this:

 

 <?php
$bottle[0]="<img src=\"images/bottlesandcaps/diamondbottles/smalldiamonddarkblue.gif\">";
$bottle[1]="<img src=\"images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif\">";
  echo $bottle[0];
?>

Link to comment
Share on other sites

That should work.  Your single and double quotes may be incorrect?

 

Try this:

 

<?php

$bottle[0]="<img src='images/bottlesandcaps/diamondbottles/smalldiamonddarkblue.gif'>";

$bottle[1]="<img src='images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif'>";

  echo $bottle[0];

?>

Link to comment
Share on other sites

just before we get crap loads of if's

 

your syntax is wrong

 

$bottle[1]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif'">';

should be

$bottle[1]='<img src="images/bottlesandcaps/diamondbottles/smalldiamonddarkclear.gif">';

 

in other words, the last part of your string has a ' to many  (should be ">';  and not '">'; )

 

besides that you are indeed missing an alt= " "  attribute as said above, but that was not breaking your syntax.

 

I did not see that :) that is one reason we use code and/or php tags

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.