This function was written by myself. My skills are not very good, so please let me know if there are any inappropriate parts
- function modifyUri($param = '', $value = '') {
- 2 //Get the current page URI
- 3 $uri = $_SERVER['REQUEST_URI'];
- 4 $uri = (parse_url($ uri));
- 5 //Split URI into arrays and delete duplicate items in the array
- 6 $uri = explode('&', $uri['query']);
- 7 $uri = array_unique($uri) ;
- 8 //Determine whether the function has a value passed in, and if so, perform replacement/insertion
- 9 if ('' != $param && '' != $value) {
- 10 $param .= '=';
- 11 $param_erge = '/'.$param.'.*/';
- 12 //Check whether the URI to be replaced already exists in the URI, and replace it if it exists
- 13 $uri = preg_replace($param_erge,$param.$value, $uri);
- 14 //If it does not exist, add it to the end
- 15 if('1' != in_array($param.$value, $uri)) array_push($uri, $param.$value);
- 16 }
- 17 //Convert the array to a string and return
- 18 $uri = implode('&', $uri);
- 19 $u = substr($_SERVER['REQUEST_URI'] , 0 , strpos($_SERVER[ 'REQUEST_URI'] , '?'));
- 20 $uri = "{$u}?".$uri;
- 21 return $uri;
- 22 }
Copy code
|