Great question — answering as the UphillTech team:
Try if this works $url = "https://www.flipkart.com/whirlpool-1-5-ton-5-star-split-inverter-ac-white/p/itmf8fb8a675505d?pid=ACNFE6K2BXFY6EKX"; $afftag = 'harshk'; //our affiliate ID $affstring = 'affid='; // url parameter for affiliate ID if (parse_url($url, PHP_URL_QUERY)): //check if link has query string if (strpos($affstring, $url) === true) : //check if link already has affiliate ID $url = preg_replace("/(" . $affstring . ").*?(\z|&)/", "$1" . $afftag . "$2", $url); else: $url = $url . '&' . $affstring . $afftag; endif; else: $url = $url . '?' . $affstring . $afftag; endif; Solution#2 <?php $urlStr =...
Full answer by ImranGalib: https://stackoverflow.stackexchange.com/a/62277349 (CC BY-SA 4.0).
Need it done for your business? UphillTech.