码迷,mamicode.com
首页 > 编程语言 > 详细

PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)

时间:2019-10-31 18:04:20      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:foo   方法   php   div   例子   echo   数组   参数   pos   

http_build_query

(PHP 5, PHP 7)

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

 

 1 <?php
 2 $data = array(
 3     ‘foo‘=>‘bar‘,
 4     ‘baz‘=>‘boom‘,
 5     ‘cow‘=>‘milk‘,
 6     ‘php‘=>‘hypertext processor‘
 7     );
 8 
 9 echo http_build_query($data);
10 /* 
11  * 输出:foo=bar&baz=boom&cow=milk&php=hypertext+processor
12 */
13 ?>
14 例子 2. http_build_query() 使用数字下标的元素
15 
16 <?php
17 $data = array(‘foo‘, ‘bar‘, ‘baz‘, ‘boom‘, ‘cow‘ => ‘milk‘, ‘php‘ =>‘hypertext processor‘);
18 
19 echo http_build_query($data);
20 /* 
21  * 输出:0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
22 */
23 
24 echo http_build_query($data, ‘myvar_‘);
25 /* 
26  * 输出:myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor
27 */
28 ?>

 

PHP使用http_build_query()构造URL字符串的方法(可将POST参数组转换拼接成GET请求链接)

标签:foo   方法   php   div   例子   echo   数组   参数   pos   

原文地址:https://www.cnblogs.com/jiayu123/p/11772673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!