将PHP代码添加到html锚标记

时间:2013-05-11 20:58:53

标签: php anchor

我正在尝试使用锚标记访问我保存在服务器上(在uploads文件夹中)的上传图像。目的是提供像缩放功能。缩放工作正常,但图像不显示。 我试过这样的事情

<?php 
 //$txt is the actual image name and $image is the name saved in uploads folder,$ext is the extension like .jpg or so.
 $image = time().substr(str_replace(" ", "_", $txt), 5).".".$ext; 
?>
HTML中的

//image isn't displayed using
<a href = "<?php echo "uploads/$image" ?>"></a> 

但如果我使用

则显示
<a href = "uploads/image.jpg"></a>.

有没有办法可以在标签中使用php代码访问图像?

2 个答案:

答案 0 :(得分:2)

您没有关闭<?PHP标记。这样做

 <a href = "<?php echo 'uploads/$image'; ?>"></a> 

答案 1 :(得分:2)

你缺少一个分号,$变量用单引号括起来,因此不会展开。

<a href="uploads/<?php echo $image; ?>">Image</a>

安东尼。

相关问题