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, '', '&'); 9 10 ?>
输出结果:
foo=bar&baz=boom&cow=milk&php=hypertext+processor foo=bar&baz=boom&cow=milk&php=hypertext+processor