What's wrong with putting spaces in $_GET variables

ionescho picture ionescho · Jun 15, 2011 · Viewed 11k times · Source

If I for example have my url looking like index.php?category=IT%20&%20Soft. Then i try to print "$_GET[category]" i only get "IT" and not "IT & Soft". What is wrong here? It's frustrating me.

Answer

Brad picture Brad · Jun 15, 2011

The problem is not the spaces, but the ampersand.

Use %26 instead, like this:

index.php?category=IT%20%26%20Soft

The ampersand indicates that you are beginning another field (like category=IT&subcategory=somethingelse). You can see a list of reserved characters on Wikipedia.