better way to replace query string value in a given url

前端 未结 8 2020
南方客
南方客 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:16

    Well, I had same problem, found this question, and, in the end, prefered my own method. Maybe it has flaws, then please tell me what are they. My solution is:

    $query=$_GET;
    $query['YOUR_NAME']=$YOUR_VAL;
    $url=$_SERVER['PHP_SELF']. '?' .  http_build_query($query);
    

    Hope it helps.

提交回复
热议问题