Adding php code to html anchor tag

邮差的信 提交于 2019-12-24 16:17:10

问题


I'm trying to access an uploaded image which i've saved on my server (in the uploads folder) using the anchor tag. 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

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


回答1:


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.




回答2:


you are not closing the <?PHP tag. do it like

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


来源:https://stackoverflow.com/questions/16501676/adding-php-code-to-html-anchor-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!