Home > Backend Development > PHP Tutorial > URI handler function

URI handler function

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template