php 在echo语句中添加php变量作为href链接地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18916966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add php variable inside echo statement as href link address?
提问by jasonbradberry
I'm trying to use a php variable to add a href value for a link in an echo statement.
我正在尝试使用 php 变量为 echo 语句中的链接添加 href 值。
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.
这是我要使用的代码的简化版本。我知道我不能只是将变量添加到 echo 语句中,但我似乎无法在任何地方找到一个有效的例子。
$link_address = '#';
echo '<a href="$link_address">Link</a>';
Any pointers appreciated.
任何指针表示赞赏。
回答by Gautam3164
Try like
试试像
HTML in PHP :
PHP 中的 HTML :
echo "<a href='".$link_address."'>Link</a>";
Or even you can try like
或者甚至你可以尝试像
echo "<a href='$link_address'>Link</a>";
Or you can use PHP in HTML like
或者您可以在 HTML 中使用 PHP,例如
PHP in HTML :
HTML 中的 PHP :
<a href="<?php echo $link_address;?>"> Link </a>
回答by Davide De Santis
you can either use
你可以使用
echo '<a href="'.$link_address.'">Link</a>';
or
或者
echo "<a href=\"$link_address\">Link</a>';
if you use double quotes you can insert the variable into the string and it will be parsed.
如果您使用双引号,您可以将变量插入字符串中,它将被解析。
回答by Ryan Paluch
Basically like this,
基本上是这样的
<?php
$link = ""; // Link goes here!
print "<a href="'.$link.'">Link</a>";
?>
回答by Jay
as simple as that: echo '<a href="'.$link_address.'">Link</a>';
就如此容易: echo '<a href="'.$link_address.'">Link</a>';
回答by Alaa Moneam
If you want to print in the tabular form with, then you can use this:
如果要以表格形式打印,则可以使用:
echo "<tr> <td><h3> ".$cat['id']."</h3></td><td><h3> ".$cat['title']."<h3></</td><td> <h3>".$cat['desc']."</h3></td><td><h3> ".$cat['process']."%"."<a href='taskUpdate.php' >Update</a>"."</h3></td></tr>" ;