Change the PHP Query String Variable Separator Using php.ini

By  on  

As you probably know, the default PHP query string variable separator is the "&" character. One annoyance with using the "&" character is that, in order to have valid XHTML syntax, you need to output your &'s as "&". If you'd like to avoid all of that mess, you can simply change the separating character to a semi-colon (;). Here's how:

The PHP

//inside the php.ini file
arg_separator.input = ";"

//example URL:  /page.php?key1=value1;key2=value2;key3=value3

There you go -- one easy step to outputting cleaner URLs. Do any of you use this method?

Recent Features

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

  • By
    MooTools ASCII Art

    I didn't realize that I truly was a nerd until I could admit to myself that ASCII art was better than the pieces Picasso, Monet, or Van Gogh could create.  ASCII art is unmatched in its beauty, simplicity, and ... OK, well, I'm being ridiculous;  ASCII...

  • By
    CSS Tooltips

    We all know that you can make shapes with CSS and a single HTML element, as I've covered in my CSS Triangles and CSS Circles posts.  Triangles and circles are fairly simply though, so as CSS advances, we need to stretch the boundaries...

Discussion

  1. Personally I set it to & which validates fine.

    and if you don’t have access to the ini file the following works:

    ini_set('arg_separator.output','&');
  2. pretty useful

  3. Didnt know this one, thx ;)

  4. And how Search engines see on this trick?

  5. @wsr: Search engine sees it as the same — you wouldn’t be penalized by this.

  6. @david: Maybe, but standart is “&” and many SE use this symbol to explode and analyze query string…

  7. I think this will break a 3rd party CMS(like wordpress).

  8. Alex

    Think SEO

  9. If you really want to display pretty URLs it’s better to use mod_rewrite.

  10. Keep in mind that XML invalidates the & symbol when it’s located in the href tag.
    To validate your XML you have to supply & EG: href=”?i=1&x=2″
    When using this method the return value in the URI will return as “&”, and if you are using relative URLs in your application navigation, this will invalidate the DOM generated XML in most browsers and stop page load in Google Chrome (Safari).
    Result: href=”/mypage.php?i=1&x=2″

    Returns – EntityRef: expecting ‘;’

  11. To fix the above the first example href=”?i=1&x=2″ should read with &
    like so
    href=”?i=1&x=2″

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!