Jump to content

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


street9009

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.