PHP add/modify a query string param & get the URL

后端 未结 2 576
情深已故
情深已故 2021-02-05 23:39

How can redirect the user back to the same page with the existing Query Strings but have 1 added/modified like \"page\".

I suppose 1 method is:

  1. parse the
2条回答
  •  隐瞒了意图╮
    2021-02-06 00:18

    Using Jim Rubinstein's answer, I came up with a useful function that I thought I might share:

      function modQuery($add_to, $rem_from = array(), $clear_all = false){
      if ($clear_all){
         $query_string = array();
      }else{
         parse_str($_SERVER['QUERY_STRING'], $query_string);
      }
      if (!is_array($add_to)){ $add_to = array(); }
      $query_string = array_merge($query_string, $add_to);
      if (!is_array($rem_from)){ $rem_from = array($rem_from); }
      foreach($rem_from as $key){
         unset($query_string[$key]);
      }
      return http_build_query($query_string);
      }
    

    For example: Feature

提交回复
热议问题