vikyd / to_php_post_arr

Convert python dict/list/nested to PHP Array like urlencoded string

Home Page:https://pypi.python.org/pypi/to-php-post-arr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert python dict/list/nested to PHP Array like urlencoded string

中文说明

Install

pip install to_php_post_arr

Usage

from to_php_post_arr.convert import recursive_urlencode

a = [1, 2]
print(recursive_urlencode(a))
# 0=1&1=2


a2 = (1, '2')
print(recursive_urlencode(a2))
# 0=1&1=2


b = {'a': 11, 'b': 'foo'}
print(recursive_urlencode(b))
# a=11&b=foo


c = {'a': 11, 'b': [1, 2]}
print(recursive_urlencode(c))
# a=11&b[0]=1&b[1]=2


d = [1, {'a': 11, 'b': 22}]
print(recursive_urlencode(d))
# 0=1&1[a]=11&1[b]=22


e = {'a': 11, 'b': [1, {'c': 123}, [3, 'foo']]}
print(recursive_urlencode(e))
# a=11&b[0]=1&b[1][c]=123&b[2][0]=3&b[2][1]=foo

f = ['测试中文']
print(recursive_urlencode(f))
# test chinese 
# 0=%E6%B5%8B%E8%AF%95%E4%B8%AD%E6%96%87

PHP urlencoded Array Data

Test

cd tests

python -m unittest test_convert

Thanks

About

Convert python dict/list/nested to PHP Array like urlencoded string

https://pypi.python.org/pypi/to-php-post-arr

License:MIT License


Languages

Language:Python 100.0%