http_build_query ... argh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi guys,

long story ahead - the question at the end concerns whether
the solution to my problem is obviously flawed (as far as anyone can see)
and whether there might be a better/faster solution....

apparently http_build_query() has been 'fixed' so that it now
urlencodes square brackets (and if you have never used square brackets in
a url pointing a php script then your obviously new here ;-)

this is fine - apart from the fact that I have a rather complex generic thingy
that not only uses http_build_query() to build actual URLs but
also to generate the input names of hidden form fields (sometimes
one needs/wants to place a stack of request arguments as hidden inputs
instead of as GET parameters of a URL.

urlencoded sqaurebrackets in a POST variable's name will not be deencoded,
and as a result php won't see the POST vars as 'arrays' (which the
square brackets signify). upshot being that my app is borked.

so now I'm trying to fix the issue - the only real remedy being to
perform some kind of string replacement on the output of http_build_query()
in situations where it is relevant (i.e. situations where I'm not using the
result of http_build_query() [directly] in an actual URL)

so I wrote a function which is supposed to take a string and decode every
urlencoded opening and closing square bracket that occurs between a question mark/ampersand
and an equals sign (I don't want to decode urlencoded square brackets that might
exist in the values of params), I tested it and it seems to work but someone
might feel the urge to tell me I'm forgeting something or merely that my solution
is slow as molasses and that there is a better way...

here is the function:

function inputPostQueryUnBorker($s)
{
        return preg_replace('#(\?|&(?:amp;)?)([^=]*)=#eU',
                            "'\\1'.str_replace(array('%5B','%5D'), array('[',']'), '\\2').'='",
                            $s);
}

so how bad is it?

tia.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux