PsP
PsP

Reputation: 696

My images are not shown in php

Hi I'm new to PHP and I've tried online docs for writing syntaxes for displaying images in web browsers. When I try this code:

echo '<img src="/netbeans/PhpProject2/Plate.jpg" alt ="Test" />';

I'm able to see the images in the web browser but when I try the alternative one:

$image_address = "/netbeans/PhpProject2/Plate.jpg";
echo '<img src=$image_address alt ="Test" />';

I'm not able to see anything ! I also tried:

echo '<img src="$image_address" alt ="Test" />';

and

echo '<img src='.$image_address.' alt ="Test" />';

but nothing happened ... what's wrong ....? how can I put the address in a variable and then show it in the web browser ... I know that my address should begin from the localhost...

Upvotes: 1

Views: 41

Answers (2)

sybear
sybear

Reputation: 7784

The best syntax for this would be:

echo "<img src='{$image_address}' alt='Test' />";

Upvotes: 1

Surround it by double quotes instead of single quotes.

echo "<img src=$image_address alt ='Test' />";

That is because variables will not be parsed inside single quotes.

You could alternatively use these too..

echo "<img src=".$image_address." alt ='Test' />";
echo "<img src='$image_address' alt ='Test' />";

Upvotes: 1

Related Questions