TEXT   89
munge uri
Guest on 16th March 2023 12:19:14 AM


  1. function munge_uri($variable_to_munge="", $query="") {
  2.  
  3.  
  4.   if (strlen($query) < 1) {
  5.     global $QUERY_STRING;
  6.     $query = $QUERY_STRING;
  7.   }
  8.  
  9.   if (substr($query, 0, 1) == "?") {
  10.     $query = substr($query, 1, strlen($query)-1);
  11.   }
  12.  
  13.  
  14.   $buf = "";
  15.  
  16.   $vars = split("&", $query);
  17.  
  18.   #print_r($vars);
  19.  
  20.   $middle = strpos($variable_to_munge, "=");
  21.   foreach ($vars as $var) {
  22.  
  23.     if ( substr($var, 0, $middle) == substr($variable_to_munge, 0, $middle) ) {
  24.       # we don't add it here... because if a munged variable doesnt previously exist, we still want to add it at the end.
  25.      
  26.     } else {
  27.       $buf = $buf . $var . "&";
  28.     }
  29.    
  30.   }
  31.  
  32.    
  33.     #add the replacement variable here... so it will show even if it is new
  34.     $buf = $buf . $variable_to_munge;
  35.  
  36.  
  37.   # we need a ?, but we don't want to have ?????? buildup if we call this repeatedly on a string.
  38.   if (substr($buf, 0, 1) != "?") {
  39.     $buf = "?" . $buf;
  40.   }
  41.    
  42.   return $buf;
  43.    
  44.    
  45.  
  46. }

Raw Paste

Login or Register to edit or fork this paste. It's free.