PHP:如何在不显示整个 URL 地址的情况下回显 URL 链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4830459/
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
PHP: How to echo an URL link without displaying the whole url address
提问by woel
How do we echo this url link so it displays a link named View
instead of the long generated url address? It's this currently I'm using:
我们如何回显这个 url 链接,以便它显示一个名为的链接View
而不是长生成的 url 地址?这是我目前正在使用的:
echo($value->url."<br>");
echo($value->url."<br>");
The output of the code above would give me the whole url address, so can someone writes how if I want it to be a simple link
named View
? Thanks..
上面代码的输出会给我整个 url 地址,所以如果我希望它是一个简单的link
命名,有人可以写下如何View
吗?谢谢..
P.S The above code currently doesn't display the url in link, I want it to be a click-able link named View
.
PS 上面的代码目前没有在链接中显示 url,我希望它是一个名为View
.
回答by Aston
echo '<a href="'.$value->url.'">View</a>';
回答by goto-bus-stop
echo '<a href="'.$value->url.'">View</a>';
echo '<a href="'.$value->url.'">View</a>';
回答by Tony L.
<?php echo '<a href="',$value->url,'">View</a>"'; ?>
use some html in it.
在其中使用一些 html。
回答by Leo
I'm surprised that nobody answered with the 'Cake' way to do this. For a straight link, you'll have to tinker a little as the helper expects a path relative to controllers, but it's not difficult. It's the best way to do it if your url is internal to the site, i.e. an action/view handled by CakePHP.
我很惊讶没有人用“蛋糕”的方式来回答这个问题。对于直接链接,您必须稍加修改,因为帮助程序需要相对于控制器的路径,但这并不困难。如果您的 url 位于站点内部,即由 CakePHP 处理的操作/视图,那么这是最好的方法。
<?php echo $html->link('View', $value->url); ?>
http://book.cakephp.org/view/1442/link
http://book.cakephp.org/view/1442/link
edit:
编辑:
...and of course a better way to do it in PHP would be to leverage the double quote parsing -
...当然,在 PHP 中更好的方法是利用双引号解析 -
<?php echo "<a href='$url'>View</a>"; ?>
or, if you want to be picky,
或者,如果你想挑剔,
<?php echo "<a href=\"$url\">View</a>"; ?>
回答by tijnn
this way worked for me:
这种方式对我有用:
<td><?php print "<a href='$row[website]'> go </a>"; ?></td>