Any one have the ultimate PHP function(s) to add/remove parameters from a query string? It needs to handle all possible cases, Ive seen ones that handle some cases, but not all.
Bazı örnek vakalar:
- http://mysite.com?param1=1¶m2=2
- http://www.mysite.com/?param1 [] = 1 ve param1 [] = 2
- ftp://user:pass@mysite.com/files/uploads/? Param1 = 1 & param2 = 2
- /? Param1 = 1 & param2 = 2
- / Sayfa.html? Param1 = 1
- / Dir / sayfa.html? Testi = 1 & bla = 2
- /dir/ Sayfa.html? Param1 = 1#jump_to_bottom
Bu ideal gibi bir şey olmalıdır:
function add_get_param($uri, $name, $value = null) { ... }
function remove_get_param($uri, $name) { ... }
Bazı örnek testler:
$var = add_get_param('http://mysite.com?param1=1¶m2=2', 'param3', 3);
// http://mysite.com?param1=1¶m2=2¶m3=3
ve:
$var = add_get_param('/dir/ Sayfa.html? Param1 = 1¶m2=2#jump_to_bottom', 'param3');
// /dir/ Sayfa.html? Param1 = 1¶m2=2¶m3#jump_to_bottom
vs ..
Alright, I wrote my own functions:
PHP: http://pastebin.org/170157 jQuery: http://pastebin.org/169981