在HTML标签内使用PHP变量? [英] Using PHP variables inside HTML tags?

查看:108
本文介绍了在HTML标签内使用PHP变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对php很新,但是我在这个问题上陷入困境......假设我等待给一个给定参数的另一个站点的链接,我该怎么做correclty?



这就是我现在的情况:

 < html> 
< body>
<?php
$ param =test;

echo< a href =http://www.whatever.com/$param>点击此处< / a>;
?>




解决方案<对于初学者来说,您可能不想过度使用回声,因为(就像您的情况一样),您可以很容易地在引号上犯错。



这可以解决您的问题:

  echo< a href = \http://www.whatever .com / $ param \>点击这里< / a>; 

真的是这样做的

 <?php 
$ param =test;
?>
< a href =http://www.whatever.com/< ;?php echo $ param; ?>>点击此处< / a>


I am pretty new to php but I'm stuck on this problem... Say i wait to put a link to another site with a given parameter, how do I do it correclty?

This is what i have now:

<html>
<body>
<?php
  $param = "test";

  echo "<a href="http://www.whatever.com/$param">Click Here</a>;
?>

</body>
</html>

解决方案

Well, for starters, you might not wanna overuse echo, because (as is the problem in your case) you can very easily make mistakes on quotation marks.

This would fix your problem:

echo "<a href=\"http://www.whatever.com/$param\">Click Here</a>";

but you should really do this

<?php
  $param = "test";
?>
<a href="http://www.whatever.com/<?php echo $param; ?>">Click Here</a>

这篇关于在HTML标签内使用PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆