Ruby function similar to parse_str in php?

Posted by jolierouge on Stack Overflow See other posts from Stack Overflow or by jolierouge
Published on 2010-06-09T17:50:28Z Indexed on 2010/06/09 17:52 UTC
Read the original article Hit count: 229

Filed under:
|

Hi,

I need to parse a string like this: a[metadata][][name]=dont|do|this&a[name]=Hello World&a[metadata][][value]=i|really|mean it

CGI::parse gives me this:

{"a[name]"=>["Hello World"], "a[metadata][][name]"=>["dont|do|this"], "a[metadata][][value]"=>["i|really|mean it"]}

I would like something like what PHP does with parse_str, which when given the same string does this:

Array
(
    [a] => Array
        (
            [metadata] => Array
                (
                    [0] => Array
                        (
                            [name] => dont|do|this
                        )

                    [1] => Array
                        (
                            [value] => i|really|mean it
                        )

                )

            [name] => Hello World
        ))

Any help would be awesome.

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about ruby