parsing - Parse string containing dots in php -
i parse following string:
$str = 'procedurescustomer.tipi_id=10&procedurescustomer.id=1'; parse_str($str,$f);
i wish $f parsed into:
array( 'procedurescustomer.tipi_id' => '10', 'procedurescustomer.id' => '1' )
actually, parse_str
returns
array( 'procedurescustomer_tipi_id' => '10', 'procedurescustomer_id' => '1' )
beside writing own function, know if there php function that?
from php manual:
dots , spaces in variable names converted underscores. example
<input name="a.b" />
becomes$_request["a_b"]
.
so, not possible. parse_str()
convert periods underscores. if can't avoid using periods in query variable names, have write custom function achieve this.
the following function (taken this answer) converts names of each key-value pair in query string corresponding hexadecimal form , parse_str()
on it. then, they're reverted original form. way, periods aren't touched:
function parse_qs($data) { $data = preg_replace_callback('/(?:^|(?<=&))[^=[]+/', function($match) { return bin2hex(urldecode($match[0])); }, $data); parse_str($data, $values); return array_combine(array_map('hex2bin', array_keys($values)), $values); }
example usage:
$data = parse_qs($_server['query_string']);
Comments
Post a Comment