Insert a string before the end of a link

邮差的信 提交于 2019-12-24 12:51:50

问题


What's the fastest way to insert a string before the </a> tag?

<a href="..."> bla bla... </a>

回答1:


str_replace("</a>", "blabla</a>", $text);



回答2:


There are many, many ways to skin this cat, but here are a few common ones:

IN HTML:

<a href=""><?php echo $foo; ?></a>
<a href=""><?=$foo?></a>

IN PHP

echo "<a href=\"\">$foo</a>";
echo "<a href=\"\">{$foo}</a>";
echo "<a href=\"\">". $foo ."</a>";

Edit, you said "fastest", which I overlooked

Assuming we are talking about PHP, specifically: Supposedly using the comma for string concatenation in php is one of the fastest ways to build a string. But unless you are doing this an awful lot, this seems like an optimization that won't buy you very much.

echo "<a href=\"\">", $foo ,"</a>";



回答3:


<a href="..."> bla bla... <?php echo "string"; ?></a>



来源:https://stackoverflow.com/questions/4349982/insert-a-string-before-the-end-of-a-link

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