2014-09-26 73 views
-1

我想在我的网页上使用PHP脚本显示图像以确定显示哪个图像。 图片链接如下:PHP回显显示图像HTML

<a href="gallery.php?image=image01">......</a> 

我的PHP脚本是这样的:

<?php 
$result = $_GET['image']; 
echo '<img src="images/gallery/'.$result.'.jpg">'; 
?> 

那么我想在HTML方面实现的是:

<img src="images/gallery/image01.jpg"> 

结果我得到的是'';?>''在页面上显示。 任何帮助将不胜感激!

+1

看来,您的服务器不实际执行PHP,只是吐出原始文本,你的代码。 – durbnpoisn 2014-09-26 17:54:35

+0

我没有DV,但根据它的外观,目前的答案没有解决OP的问题。 – 2014-09-26 18:02:20

+0

nope @durbnpoisn我认为它是因为他没有正确地关闭引号。 – Lal 2014-09-26 18:09:14

回答

0

我的gallery.php改成这样:

<?php $result = $_GET['image']; ?> 
<img src="images/gallery/<?php echo $result; ?>.jpg"> 

这只会一点点。您应该回显结果以查看将变量传递给图库页面时所获得的结果。

+1

你需要在这里关闭你的'php' ...'<?php $ result = $ _GET ['image']; ?> Rasclatt 2014-09-26 18:14:48

+0

结合@ Rasclatt的建议,这对我工作,谢谢!! – petehallw 2014-09-26 18:18:48

+0

@petehallw多数民众赞成在其实我的回答:) – ExCluSiv3 2014-09-26 18:19:52

1

你使用echo错误,这里是你应该如何使用它。

<?php 
$result = $_GET['image']; 
?> 

<img src="images/gallery/<?php echo $result ?>.jpg"> 
+0

这工作,谢谢你!但我不得不选择第一个正确的答案:) – petehallw 2014-09-26 18:19:25

+0

为什么有人downvoted这个答案? – ExCluSiv3 2014-09-26 18:51:50

2

你必须改变这样的

<?php 
$result = $_GET['image']; 
?> 
<img src="images/gallery/<?php echo $result; ?>.jpg"> 
2
<?php 
    $result = filter_input (INPUT_GET , 'image'); 
    if (isset($result) && !empty($result)) { 
     echo '<img src="images/gallery/'.$result.'.jpg">'; 
    } 
?> 
+0

我认为它为他先进的,虽然做得很好,外面的框想:) – ExCluSiv3 2014-09-26 18:19:15