PHP » PYTHON |
login |
register |
about
|
# coding: utf-8 from urllib.parse import unquote_plus import re def get_http_vars(text, encoding='utf-8'): """Gets PHP-like HTTP superglobal variable. :arg str text: query string :arg str encoding: input encoding :returns: dict """ for pair in text.split('&'): pair = pair.split('=', 1) key = unquote_plus(pair[0], encoding=encoding) if key == '' or key[0] == '[': continue value = unquote_plus(pair[1], encoding=elf._encoding) if len(pair) > 1 else '' m = re.search(r'^([^\[]+)\[(.*)\]$', key) if not m: data[key] = value continue subkeys = [m.group(1)] + m.group(2).split('][') last_index = len(subkeys) - 1 subdata = data for i in range(last_index): if subkeys[i] == '': subvalue = [] if subkeys[i + 1] == '' else {} subdata.append(subvalue) else: if subkeys[i] in subdata: subvalue = subdata[subkeys[i]] else: subvalue = [] if subkeys[i + 1] == '' else {} subdata[subkeys[i]] = subvalue subdata = subvalue if subkeys[last_index] == '': subdata.append(value) else: subdata[subkeys[last_index]] = value return data $_POST$HTTP_POST_VARS [deprecated]$_POST -- $HTTP_POST_VARS [deprecated] — HTTP POST variables DescriptionAn associative array of variables passed to the current script via the HTTP POST method. $HTTP_POST_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such) Changelog
Examples
Example #1 $_POST example
<?php Assuming the user POSTed name=Hannes The above example will output something similar to: Hello Hannes!
Notes
|
more
Recently updated
more
Most requested
more
Last requests
|