Re: String to Array or Hash Table
| From: | Duncan Hill | Date: | Sun, 19 Oct 2003 16:54:02 +0000 |
| Subject: | Re: String to Array or Hash Table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-166665@lists.php.net to get a copy of this message | ||
sun zheng said:
>>tx for the reply.. ya, it is what i am looking for.. however, your solution
>>is not the right one.. please help me to adjust it a lot..
>>
>>let us come back to the initial string ..
>>"approved=yes&error=&authnumber=025968&transactionnumber=313869";
>
>>I definately want to get something like
>>$value_array['approved'] is "yes"
>>$value_array['error'] is ""
>>$value_array['authnumber'] is "025968"
>>$value_array['transactionnumber'] is "313869"
> If it's just a string, something like:
> $data_array = split('&', $string);
> foreach ($data_array as $key) {
> list($mykey, $value) = split('=', $key);
> $value_array[$mykey] = $value;
> }
> ###################################################
>
> thank you.. but .. it is still different as what i expect... :(
>
> ya, it is only a string, not a link which could be captured by $_get[].. :(
> "approved=yes&error=&authnumber=025968&transactionnumber=313869"
>
> let's just take a look at your final array "$value_array[$mykey] = $value;"
>
> key <-> content will be
> 0 - approved
> 1 - yes
> 2 - error
> 3 - null
> 4 - authnumber
> 5 - 025968
> 6 - transactionnumber
> 7 - 313869
I stated that the code was untested. If I didn't, oops. Massaging it into a
format you can use is left as an excercise for the reader - it is not my aim
to provide fully working, tested code when I have better ways to spend my time
:)
print_r($var) is your friend, apply liberally at critical stages to see if the
data is in the format you want.