[ create a new paste ] login | about

Link: http://codepad.org/p7sgh933    [ raw code | output | fork ]

PHP, pasted on Jun 19:
1
2
3
4
5
6
7
8
9
10
11
12
<?php
$string = 'variable1=true&variable2=1,2,3&variable3="test"&variable4!=true&variable5!=4,5,6&variable!="test"';
$pairs = explode('&', $string);
foreach ($pairs as $pair) {
    if (strstr($pair, '!=')) {
        list($key, $value) = explode('!=', $pair);
    } else {
        list($key, $value) = explode('=', $pair);
    }
    $values[$key] = $value;
}
print_r($values);


Output:
1
2
3
4
5
6
7
8
9
Array
(
    [variable1] => true
    [variable2] => 1,2,3
    [variable3] => "test"
    [variable4] => true
    [variable5] => 4,5,6
    [variable] => "test"
)


Create a new paste based on this one


Comments: