street9009 Posted September 27, 2007 Share Posted September 27, 2007 Hello all, I have a site where URLs have parameters in them, and they can be multi-worded (separated by a +) and can also have special characters. So for instance, there's an "Odds & Ends" link that when you click, it sets this: Cat1=Odds+%26+Ends. I need to get that text and transform it back to "Odds & Ends" and stick it in a string variable. This is probably fairly easy but I am a little lost on the best way to do that. What's the best way to transform a $_GET back to a "normal" string? It's important to note that the $_GET could be one word or many and may or may not have the special characters in them. I'd appreciate any help anyone can provide. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/70922-solved-multi-worded-_get-parameters-with-special-characters/ Share on other sites More sharing options...
KevinM1 Posted September 27, 2007 Share Posted September 27, 2007 Hello all, I have a site where URLs have parameters in them, and they can be multi-worded (separated by a +) and can also have special characters. So for instance, there's an "Odds & Ends" link that when you click, it sets this: Cat1=Odds+%26+Ends. I need to get that text and transform it back to "Odds & Ends" and stick it in a string variable. This is probably fairly easy but I am a little lost on the best way to do that. What's the best way to transform a $_GET back to a "normal" string? It's important to note that the $_GET could be one word or many and may or may not have the special characters in them. I'd appreciate any help anyone can provide. Thanks. To transform a string to/from a url-friendly form, the urlencode()/urldecode() functions are typically used: <?php //transforming a string into a url-friendly form: $string = "cat=odds&ends"; if($something){ header("Location: anotherscript.php?" . urlencode($string)); } . . . . //transforming the url into something we can use: if(isset($_GET['cat']) && !empty($_GET['cat'])){ $cat = urldecode($_GET['cat']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70922-solved-multi-worded-_get-parameters-with-special-characters/#findComment-356546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.