I’ve created my own newsletter module and come across one (big) problem.
The system formats all urls with additional parameters to keep track of the clicks in google analytics.
e.g.
A url like this
becomes like this
http://www.domain.com/&utm_source=newsletter&utm_medium=e-mail&utm_campaign=test
and a url like this
becomes like this
http://www.domain.com/?page=1&utm_source=newsletter&utm_medium=e-mail&utm_campaign=test
The first example is bogus. I know the first ampersand has to be replaced by an ampersand and that’s where the problem occurs.
I’m using this pattern to extract url’s
$pattern = array('#[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%\{\}])*#');
$replace = array('\\0&utm_source=newsletter&utm_medium=e-mail&utm_campaign=test');
$body = preg_replace($pattern,$replace,$body);
Can anybody help me with a correct and working regex, so the first url parameter always contains a questionmark in stead of an ampersand?
just use