问一个关于parse_str函数的问题

WBOY
Release: 2016-06-20 12:26:03
Original
1290 people have browsed it

parse_str函数很好用,可以把字符串转换为数组,并且还带有索引。可是,如果索引值中有  . 号,它就会自动把它转换为下划线。例如:

$key = "现代教育技术"; 

$postd[1]="course.title=";
 $postdd=$postd[1].$key;
parse_str($postdd,$fields);
   print_r($fields);

怎么样让parse_str函数不把点号转换为下划线呢。


回复讨论(解决方案)

parse_str 是按 HTTP协议 的约定进行工作的
键名中的 . (点)被换成 _ (下划线)是 http 协议为防止歧义而做的约定
 如果你想原样转化,就得自己编写代码

$s = 'a.1=2&b.2=3';$p = '/&(?!amp;)/';foreach(preg_split($p, $s) as $v) {  $t = explode('=', $v);  $r[$t[0]] = $t[1];}print_r($r);
Copy after login
Array(    [a.1] => 2    [b.2] => 3)
Copy after login

method1=1&keyzy=name&keyword=现代教育技术

可上面这个字符串解析之后就变成了

Array ( [method1] => 1 )

是吗?

$s = 'method1=1&keyzy=name&keyword=现代教育技术';$p = '/&(?!amp;)/';foreach(preg_split($p, $s) as $v) {  $t = explode('=', $v);  $r[$t[0]] = $t[1];}print_r($r);
Copy after login
Array(    [method1] => 1    [keyzy] => name    [keyword] => 现代教育技术)
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template