Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4238 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16900 invoked by uid 1010); 28 Aug 2003 21:31:55 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16705 invoked from network); 28 Aug 2003 21:31:49 -0000 Received: from unknown (HELO asuka.nerv) (24.112.18.98) by pb1.pair.com with SMTP; 28 Aug 2003 21:31:49 -0000 Received: (qmail 24868 invoked from network); 28 Aug 2003 15:28:18 -0000 Received: from rei.nerv (HELO dummy.com) (rei@192.168.1.1) by asuka.nerv with SMTP; 28 Aug 2003 15:28:18 -0000 Reply-To: ilia@prohost.org To: "Sara Golemon" , internals@lists.php.net Date: Thu, 28 Aug 2003 17:42:35 -0400 User-Agent: KMail/1.5.3 References: <20030828211521.99071.qmail@pb1.pair.com> In-Reply-To: <20030828211521.99071.qmail@pb1.pair.com> Organization: Prohost.org MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200308281742.35888.ilia@prohost.org> Subject: Re: [PHP-DEV] Proposed Function: urlencode_array From: ilia@prohost.org (Ilia Alshanetsky) I all my time coding PHP I have yet to encounter where such a function would be useful. It most cases, it would be simpler to generate the final data rather then 2 source arrays, which then will be used to generate the final query string. The one possible issue that I see is people using urlencode_array($_GET) and forgetting about things like magic_quotes_gpc resulting in data corruption etc... Many people also do quite a bit of input validation and usually re-use the same code to build the query string for subsequent pages. -0.5 Ilia On August 28, 2003 05:16 pm, Sara Golemon wrote: > proto urlencode_array(array formdata [, string numeric_prefix]) > > Purpose: Generate a form encoded query string from an associative (or > indexed) array. > > Example: > > $formdata = array('page'=>'home', > > 'users'=>array('bob'=>array('fname'=>'Bob','lname'=>'Smith'), > > 'jdoe'=>array('fname'=>'Jane','lname'=>'Doe')), > 'errors'=>array('missing date','missing > time','sums not =='), > 'other data'); > > echo urlencode_array($formdata); > /* outputs the following > > page=home&users[bob][fname]=Bob&users[bob][lname]=Smith&users[jdoe][fname]= >J > ane&users[jdoe][lname]=Doe&errors[0]=missing+date&errors[1]=missing+time&er >r ors[2]=sums+not+%3D%3D&0=other+data > */ > > Example 2: > > Same array as above but encoded using a prefix for numeric values: > > echo urlencode_array($formdata, 'misc_'); > > page=home&users[bob][fname]=Bob&users[bob][lname]=Smith&users[jdoe][fname]= >J > ane&users[jdoe][lname]=Doe&errors[0]=missing+date&errors[1]=missing+time&er >r ors[2]=sums+not+%3D%3D&misc_0=other+data > > > Note Example 2 allows numerically indexed arrays to generate query strings > which will yield legal variable names, but doesn't enforce such behavior. > Also, the numeric_prefix only applies to the root array's indexes since > subsequence arrays may be indexed without compromise. > > The patch is available at: > http://frankenbox.alphaweb.net/test/urlencode_array.diff.txt > > The underlying function php_url_encode_hash() is meant for later use in > http_request() and for handling a context option in the http:// wrapper, > but it seems as though there's no harm exporting it to userland. (Hence the > addition of urlencode_array() -- I'm flexible on the name, > array_urlencode() has been suggested as well) > > I'm looking for a couple +1s before I actually commit this though. > > -Sara