Skip to the content...

Welcome to the David Walsh Blog. I'm a MooTools, Dojo, jQuery, CSS, and PHP Web Developer located in Madison, Wisconsin, United States. Please contact me if I can make your experience on my website better.

Change the PHP Query String Variable Separator Using php.ini

12 Responses »

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?

Discussion

  1. October 17, 2008 @ 7:56 am

    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. October 17, 2008 @ 8:36 am

    pretty useful

  3. October 17, 2008 @ 9:01 am

    Didnt know this one, thx ;)

  4. October 17, 2008 @ 11:16 am

    And how Search engines see on this trick?

  5. October 17, 2008 @ 11:22 am

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

  6. October 17, 2008 @ 11:41 am

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

  7. October 17, 2008 @ 11:42 pm

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

  8. alex
    October 18, 2008 @ 6:05 am

    Think SEO

  9. December 14, 2009 @ 10:09 am

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

  10. March 10, 2010 @ 10:24 pm

    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. March 10, 2010 @ 10:28 pm

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

Be Heard!

Share your thoughts with fellow developers of all skill levels! I want to hear from you!

Name*:
Email*:
Website:  
Wrap your code with <code> tags, f00!