生成URL编码请求字符串和解析URL编码请求字符串



http_build_query — 生成 URL-encode 以后的请求字符串php

Example #1 http_build_query() 使用示例ui

<?php
$data = array('foo'=>'bar',
               'baz'=>'boom',
               'cow'=>'milk',
               'php'=>'hypertext processor');

echo http_build_query($data) . "\n";
echo http_build_query($data, '', '&amp;');

?>

以上例程会输出:code

<strong>foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar</strong>&amp;<strong>baz=boom</strong>&amp;<strong>cow=milk</strong>&amp;<strong>php=hypertext+processor</strong>


parse_str — 将字符串解析成多个变量字符串

Example #1 parse_str() 的使用class

<?php
$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz

parse_str($str, $output);
echo $output['first'];  // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

?>