NYCPHP Meetup

NYPHP.org

[nycphp-talk] How to pass on variables with POST without using a form

Baer, Jon jbaer at VillageVoice.com
Thu Sep 21 11:25:33 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It's also available as a PEAR PHP-Compact function ...

http://pear.php.net/manual/en/package.php.php-compat.components.php 

- - Jon

- -----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of Dan Cech
Sent: Thursday, September 21, 2006 7:28 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] How to pass on variables with POST without
using a form

Cliff Hirsch wrote:
> Why not just use the built-in function http_build_query?

Maybe because it's php5-only?

If you want a php4 version, try this function I just cooked up which
duplicates all the documented functionality of the php5 function.

function http_build_query($formdata,$numeric_prefix = '',$arg_separator
= null,$_parent = null) {
    if (empty($arg_separator)) {
        $arg_separator = ini_get('arg_separator.output');
    }

    $postdata = array();
    foreach ($formdata as $k => $v) {
        if (!empty($_parent)) {
            $k = $_parent .'['. urlencode($k) .']';
        } else {
            if (is_numeric($k)) {
                $k = $numeric_prefix . $k;
            }
            $k = urlencode($k);
        }
        if (is_array($v)) {
            $postdata[] =
http_build_query($v,$numeric_prefix,$arg_separator,$k);
        } else {
            $postdata[] = $k .'=' . urlencode($v);
        }
    }

    return implode($arg_separator,$postdata);
}

Dan

> -------
> The easiest way I've found to do this is as follows:
> 
> $myvars = array(
>   'item1' => 'value1',
>   'item2' => 'value2',
> );
> 
> $postdata = array();
> foreach ($myvars as $k => $v) {
>   $postdata[] = urlencode($k) .'=' . urlencode($v); } $postdata = 
> implode('&',$postdata);

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFFEq7t99e5DI8C/rsRAo2fAKCaiDT1kSjlkKxxOSGmjlcSJtnH9gCfTliS
qJ8UAW2Z41RStskr6ZOKjVY=
=yJjE
-----END PGP SIGNATURE-----



More information about the talk mailing list