Jump to content

[SOLVED] Multi-worded $_GET parameters with special characters


Recommended Posts

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.

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']);
   }
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.