0

I am trying to search through a variable and add a tracking code infront of it. For example this below is saved in database and set to variable $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>

I am wanting to prepend https://myurl.com/trackingcode?ref= to all hrefs in the block to track click-throughs. The code would look like below

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

I'm just using LandRover as an example, this could be any URL. Thanks for your help in advance.

NUGGET
  • 61
  • 5
  • `str_replace('href="', 'href="https://myurl.com/trackingcode?ref=', $string)` or use a parser and pull the `href`. – chris85 Jul 13 '17 at 00:28
  • You have not shared with your question how existing Q&A material on site is not matching your requirements therefore I've taken the liberty in good faith to close against one example of such existing Q&A material. There certainly is more existing material but unless you make the question more specific (see as well the help center for more hints on that) I have some problems to specifically nail it down to that specific answer so please bear with me in case I didn't get all details. – hakre Jul 13 '17 at 00:34

0 Answers0