better way to replace query string value in a given url

前端 未结 8 2030
南方客
南方客 2020-12-11 16:32

Okay.. so basically, say we have a link:

$url = \"http://www.site.com/index.php?sub=Mawson&state=QLD&cat=4&page=2&sort=z\";

8条回答
  •  醉话见心
    2020-12-11 17:32

     $v) {
                if ($v)
                {
                    $tmp = explode('=', $v);
                    if (sizeof($tmp ) < 2) $tmp[1] = true;
                    $queries_array[$tmp[0]] = urldecode($tmp[1]);
                }
            }
        }
        $newQueries = array_merge($queries_array,$array);
        return $cut_url[0].'?'.http_build_query($newQueries);
    }
    ?>
    

    Use like this :

    'queryValue'));
    ?>
    

    I do that this morning, it seems to work in all case. You can change / add more than one query, with the array ;)

提交回复
热议问题