开发者

Insert a string before the end of a link

开发者 https://www.devze.com 2023-01-29 06:24 出处:网络
What\'s the fastest way to insert a string before the </a> tag? <开发者_运维问答a href=\"...\"> bla bla... </a>

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

<开发者_运维问答a href="..."> bla bla... </a>


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


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>";


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

0

精彩评论

暂无评论...
验证码 换一张
取 消