Home > php教程 > php手册 > body text

php http_build_query 实现教程

WBOY
Release: 2016-06-13 11:17:28
Original
1589 people have browsed it

php http_build_query 实现教程  

http_build_query
( PHP 5中)

http_build_query -生成URL编码查询字符串

描述
字符串http_build_query (数组$ formdata [ ,字符串$ numeric_prefix [ ,字符串$ arg_separator ] ] )
生成一个URL编码的查询字符串从联想(或索引)阵列提供。

参数

formdata
可能是一个数组或对象包含属性。

数组的形式可能是一个简单的一维结构,或一个数组的数组(谁也可能包含其他的阵列) 。

numeric_prefix
如果数字指标用于基础陈列和提供这个参数,这将是prepended的数字索引内容的基础陈列只。

这是法律允许的变量名时,数据解码用PHP或其他CGI应用程序上。

arg_separator
arg_separator.output用于单独的论点,除非此参数指定的,然后使用。


返回值
返回一个URL编码字符串。

修改

版本说明
5.1.2 arg_separator参数补充。
5.1.3方括号内是转义。


实例
例如# 1简单使用http_build_query ( )

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

echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '&'); // foo=bar&baz=boom&cow=milk&php=hypertext+processor

?>
Example #2 http_build_query() with numerically index elements.

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

echo http_build_query($data) . "n";
echo http_build_query($data, 'myvar_');
?>
The above example will output:

0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor
Example #3 http_build_query() with complex arrays

$data = array('user'=>array('name'=>'Bob Smith',
                            'age'=>47,
                            'sex'=>'M',
                            'dob'=>'5/12/1956'),
              'pastimes'=>array('golf', 'opera', 'poker', 'rap'),
              'children'=>array('bobby'=>array('age'=>12,
                                               'sex'=>'M'),
                                'sally'=>array('age'=>8,
                                               'sex'=>'F')),
              'CEO');

echo http_build_query($data, 'flags_');


Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!