PHP中将查询字符串解析到数据及逆操作

parse_str() 函数把查询字符串解析到变量中

1 <?php
2 parse_str("id=23&name=John%20Adams",$myArray);
3 print_r($myArray);
4 ?>

输出结果:

Array
(
[id] => 23
[name] => John Adams
)

http_build_query 生成 URL-encode 之后的请求字符串

 1 <?php
 2 $data = array('foo'=>'bar',
 3               'baz'=>'boom',
 4               'cow'=>'milk',
 5               'php'=>'hypertext processor');
 6 
 7 echo http_build_query($data) . "\n";
 8 echo http_build_query($data, '', '&amp;');
 9 
10 ?>

输出结果:

foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
 
posted @ 2013-01-07 15:39  易木  阅读(309)  评论(0编辑  收藏  举报