[Phpwm] multiple values with same name in $_get request

Phil Beynon phil at infolinkelectronics.co.uk
Tue Jul 3 20:00:54 BST 2007


> I'm writing a page to process a load of properties that are
> passed to me as
> get variables by a flash application.
>
>
>
> There are three parameters ( prodCode, desc and price) but these are sent
> multiple times by the Flash app. A typical parameter list is below:
>
>
>
> prodCode=306045520&desc=10ft%20Fast-Set%20Pool&price=39.99&prodCod
> e=30609401
> 0&desc=8ft%20x%208ft%20Jumbo%20Bouncy%20Castle&price=79.99&prodCod
> e=32001067
> 0&desc=Cutting%20Edge%2018v%20Cordless%20Hedge%20Trimmer&price=23.99
>
>
>
> The problem I am having is that every way I try to access these
> PHP reads it
> as an array and I only get the last values.
>
>
>
> Can anyone suggest a way that I can read all the parameters.
>

Mike,

Thats easy enough, just explode it twice; once to break it up into the
grouplets, then to seperate the name / value pairs.

<?php

$incoming =
"prodCode=306045520&desc=10ft%20Fast-Set%20Pool&price=39.99&prodCode=3060940
10&desc=8ft%20x%208ft%20Jumbo%20Bouncy%20Castle&price=79.99&prodCode=3200106
70&desc=Cutting%20Edge%2018v%20Cordless%20Hedge%20Trimmer&price=23.99";

$wibble = explode("&",urldecode($incoming));
$i=0;
foreach($wibble as $value){$subwibble[$i] = explode("=",$value); $i++;}
print_r($subwibble);

?>

which will give you;

Array
(
    [0] => Array
        (
            [0] => prodCode
            [1] => 306045520
        )

    [1] => Array
        (
            [0] => desc
            [1] => 10ft Fast-Set Pool
        )

    [2] => Array
        (
            [0] => price
            [1] => 39.99
        )

    [3] => Array
        (
            [0] => prodCode
            [1] => 306094010
        )

    [4] => Array
        (
            [0] => desc
            [1] => 8ft x 8ft Jumbo Bouncy Castle
        )

    [5] => Array
        (
            [0] => price
            [1] => 79.99
        )

    [6] => Array
        (
            [0] => prodCode
            [1] => 320010670
        )

    [7] => Array
        (
            [0] => desc
            [1] => Cutting Edge 18v Cordless Hedge Trimmer
        )

    [8] => Array
        (
            [0] => price
            [1] => 23.99
        )

)

The [0] cells are pretty superflous but act as a mnemonic as to whats in [1]
I'd personally introduce a filter incase there might be an = or & embedded
anywhere in the incoming data - but these _should_ be coming through as html
entities.

If you cut and paste that into a test page watch that you dont get some
sneaky \n returns ending up in the data! :-)

Phil




More information about the Phpwm mailing list