Insert a string before the end of a link

2019-08-07 09:26发布

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

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

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-07 09:48

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楼-- · 2019-08-07 10:02
str_replace("</a>", "blabla</a>", $text);
查看更多
你好瞎i
4楼-- · 2019-08-07 10:02

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

查看更多
登录 后发表回答