在 echo 语句中添加 PHP 变量作为 href 链接地址? [英] Add PHP variable inside echo statement as href link address?
本文介绍了在 echo 语句中添加 PHP 变量作为 href 链接地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 PHP 变量为 echo 语句中的链接添加 href 值.
I'm trying to use a PHP variable to add a href value for a link in an echo statement.
这是我要使用的代码的简化版本.我知道我不能只将变量添加到 echo 语句中,但我似乎无法在任何地方找到有效的示例.
Here's a simplified version of the code I want to use. I know that I can't just add the variable into the echo statement, but I can't seem to find an example anywhere that works.
$link_address = '#';
echo '<a href="$link_address">Link</a>';
推荐答案
Try like
PHP 中的 HTML:
echo "<a href='".$link_address."'>Link</a>";
或者你也可以试试
echo "<a href='$link_address'>Link</a>";
或者你可以在 HTML 中使用 PHP
Or you can use PHP in HTML like
HTML 中的 PHP :
<a href="<?php echo $link_address;?>"> Link </a>
这篇关于在 echo 语句中添加 PHP 变量作为 href 链接地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文