3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = '%(https?://.*)\s%mU'; $str = 'Test text http://hello-world.com Test text http://google.com/file.jpg?google=1 Test text https://hell.o.wor.ld/test?qwe=qwe Test text text text http://test.test/test hello all how are you I hope you all are fine '; $utmUrl = "utm_source=source&utm_medium=email&utm_campaign=mycamp"; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); foreach ($matches as $match) $str = preg_replace('%' . $match[1] . '%', $match[1] . (strpos($match[1], '?') !== false ? '&' : '?') . $utmUrl, $str); var_dump($str);

preferences:
54.86 ms | 402 KiB | 5 Q