前置到URL PHP

时间:2017-07-13 00:20:34

标签: php regex

我正在尝试搜索变量并在其前面添加跟踪代码。例如,下面的内容保存在数据库中并设置为变量$result['block1']

<div class="actnbtns"><a class="btn btn-primary btn-block" href="https://www.landroverusa.com/experiences/lr-experience-drives/index.html">Land Rover Experience Drives</a>
<a class="btn btn-primary btn-block" href="https://www.landroverusa.com/build-your-own/index.html">BUILD YOUR OWN LAND ROVER</a>
</div>

我希望将https://myurl.com/trackingcode?ref=添加到块中的所有href以跟踪点击次数。代码如下所示

<div class="actnbtns"><a class="btn btn-primary btn-block" href="https://myurl.com/trackingcode?ref=https://www.landroverusa.com/experiences/lr-experience-drives/index.html">Land Rover Experience Drives</a>
<a class="btn btn-primary btn-block" href="https://myurl.com/trackingcode?ref=https://www.landroverusa.com/build-your-own/index.html">BUILD YOUR OWN LAND ROVER</a>
</div>

我只是使用LandRover作为示例,这可以是任何URL。感谢您的帮助。

0 个答案:

没有答案