简体   繁体   English

PHP echo function 在 HTML 链接内

[英]PHP echo function inside a HTML link

I have a PHP echo function inside of a HTML link, but it isn't working.我在 HTML 链接中有一个 PHP echo function ,但它不起作用。 I want to have an image location, defined in img src, be in part of the clickable link of the image.我希望在 img src 中定义的图像位置成为图像可点击链接的一部分。 The page will have multiple images doing the same thing, so I am trying to use PHP to automate this.该页面将有多个图像执行相同的操作,因此我尝试使用 PHP 来自动执行此操作。

<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>">
  <img src="<?php $image=troll/GrannyTroll.jpg?>" width="100" height="94" />
</a>

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.此外,您可能会考虑urlencode -ing 一些 URL 参数。

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>
<?php 
    $image = "troll/GrannyTroll.jpg"; 
?> 
<a href="http://statuspics.likeoverload.com/<?php echo $image; ?>">
<img src="<?php echo $image; ?>" width="100" height="94"/></a> 

This is really a very good query.这确实是一个非常好的查询。 I have doubt similar to this.我有类似的疑问。 How to place something like this.如何放置这样的东西。

<a href="<?php 
  if($location  == 'US') { 
     echo 'pricing-others'; 
  } else { 
     echo 'pricing'; 
  }
?>">

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括起来:

$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.第二个错误是您按错误的顺序执行此操作,您必须先定义 $image,然后才能使用它。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM