📜  WordPress 将查询字符串添加到 URL - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:43.646000             🧑  作者: Mango

代码示例2
PHPfunction shapeSpace_add_var($url, $key, $value) {
    
    $url = preg_replace('/(.*)(?|&)'. $key .'=[^&]+?(&)(.*)/i', '$1$2$4', $url .'&');
    $url = substr($url, 0, -1);
    
    if (strpos($url, '?') === false) {
        return ($url .'?'. $key .'='. $value);
    } else {
        return ($url .'&'. $key .'='. $value);
    }
}