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
https://forums.phpfreaks.com/topic/237644-images-as-variables/
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
https://forums.phpfreaks.com/topic/237644-images-as-variables/#findComment-1221154
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
https://forums.phpfreaks.com/topic/237644-images-as-variables/#findComment-1221156
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
https://forums.phpfreaks.com/topic/237644-images-as-variables/#findComment-1221159
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
https://forums.phpfreaks.com/topic/237644-images-as-variables/#findComment-1221161
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
https://forums.phpfreaks.com/topic/237644-images-as-variables/#findComment-1221163
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.