简体   繁体   English

将PHP代码添加到html锚标记

[英]Adding php code to html anchor tag

I'm trying to access an uploaded image which i've saved on my server (in the uploads folder) using the anchor tag. 我正在尝试使用锚标记访问我已保存在我的服务器(在uploads文件夹中)的上传图像。 The aim is the provide like a zoom feature. 目的是提供像缩放功能。 The zoom works fine but the image doesn't display. 缩放工作正常,但图像不显示。 i tried something like this 我试过这样的事情

<?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; 
?>

in the HTML 在HTML中

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

but displays if i use 但如果我使用则显示

<a href = "uploads/image.jpg"></a>.

is there a way i can access the images with php code in the tag? 有没有办法可以在标签中使用php代码访问图像?

you are not closing the <?PHP tag. 你没有关闭<?PHP标签。 do it like 这样做

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

You're missing a semi-colon and the $variable is enclosed in single quotes and is therefore not expanded. 您缺少一个分号,$变量用单引号括起来,因此不会展开。

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

Anthony. 安东尼。

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

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