Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > uriライブラリ > URIモジュール > decode_www_form

singleton method URI.decode_www_form

decode_www_form(str, enc=Encoding::UTF_8) -> [[String, String]]

文字列から URL-encoded form data をデコードします。

This decodes application/x-www-form-urlencoded data and returns array of key-value array. This internally uses URI.decode_www_form_component.

_charset_ hack is not supported now because the mapping from given charset to Ruby's encoding is not clear yet. see also http://www.w3.org/TR/html5/syntax.html#character-encodings-0

This refers http://www.w3.org/TR/html5/forms.html#url-encoded-form-data

ary = URI.decode_www_form("a=1&a=2&b=3")
p ary                  #=> [['a', '1'], ['a', '2'], ['b', '3']]
p ary.assoc('a').last  #=> '1'
p ary.assoc('b').last  #=> '3'
p ary.rassoc('a').last #=> '2'
p Hash[ary]            # => {"a"=>"2", "b"=>"3"}

[SEE_ALSO] URI.decode_www_form_component, URI.encode_www_form