Reputation: 13
I have a PHP echo function inside of a HTML link, but it isn't working. I want to have an image location, defined in img src, be in part of the clickable link of the image. The page will have multiple images doing the same thing, so I am trying to use PHP to automate this.
<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>">
<img src="<?php $image=troll/GrannyTroll.jpg?>" width="100" height="94" />
</a>
Upvotes: 1
Views: 4639
Reputation: 3330
Turn
<?php $image=troll/GrannyTroll.jpg?>
into
<?php echo "troll/GrannyTroll.jpg"; ?>
?
Or provide more details on what you are trying to achieve.
Also, you might consider urlencode
-ing some of those URL parameters.
Edit:
So you might try setting the variable beforehand:
<?php $image = "troll/GrannyTroll.jpg"; ?>
<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>"><img src="<?php echo $picture; ?>" width="100" height="94" /></a>
Upvotes: 3
Reputation: 346
So now i understand what you are trying to do.
One error is that you didn't enclose $image=troll/GrannyTroll.jpg
with quotes like this:
$image = 'troll/GrannyTroll.jpg';
The second error is that you do it in the wrong order, you have to define $image first, before you use it. That's what I believe you want to do:
<?php
$image = "troll/GrannyTroll.jpg";
?>
<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>"><img src="<?php echo $image; ?>" width="100" height="94"/></a>
Upvotes: 0