1 回答
TA贡献1982条经验 获得超2个赞
试试这是否有效
$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;
解决方案#2
<?php
$urlStr = "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
$url_components = parse_url($urlStr);
$params = [];
if (isset($url_components['query'])):
parse_str($url_components['query'], $params);
endif;
$url = "{$url_components['scheme']}://{$url_components['host']}{$url_components['path']}";
$params[$affstring] = $afftag;
$url .= "?" . http_build_query($params);
- 1 回答
- 0 关注
- 136 浏览
添加回答
举报