Re: http_build_query ... argh

From: Date: Fri, 10 Nov 2006 12:49:38 +0000
Subject: Re: http_build_query ... argh
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-244468@lists.php.net to get a copy of this message
Jochem Maas wrote:
Arpad Ray wrote:
return preg_replace('#%5[bd](?=[^&]*=)#ei', 'urldecode("\0")', $s);
    
could you explain your regexp - I'd like to replace my version with your (if for no other reason than that shorter code is easier to read than longer code!) BUT until I really understand your regexp I'd feel 100% comfortable making the replacement. Basically, if we find a '=' before a '&' then we know we're in the key.
The (?=) is a positive assertion, which says that the bracket must be followed by a '=', optionally with any characters except '&' in between. Here's the pattern with comments: ~
   %5[bd]      # the bracket
   (?=         # must be followed by
       [^&]*   # any characters except "&"
       =       # then a "="
) ~eix Regards, Arpad

« previous php.general (#244468) next »