分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

http_build_query 字符串拼接

发布时间:2023-09-06 01:43责任编辑:沈小雨关键词:http

http_build_query 字符串拼接

产生一个urlencode之后的请求字符串。

1.将数组转化成url问号(?)后的字符串

 1 <?php 2 ??$date=array( 3 ??????????‘name‘=>‘tane‘, 4 ??????????‘sex‘ =>1, 5 ??????????‘job‘ => ‘officer‘ 6 ??????????‘text‘ =>‘hello world‘ 7 ??); 8 ??echo http_build_query($date); 9 ??//输出 name=tane&sex=1&job=officer&text=hello+world10 ?>

2.http_build_query() 添加数字下标

$data = array(‘name‘, ‘tane‘, ‘sex‘, ?‘job‘ => ‘officer‘, ‘text‘ =>‘hello world‘); ??echo http_build_query($date,‘remot_‘); ??//输出 remot_0=name&remote_1=tane&remot_2=sex&job=officer&text=hello+world

3.http_build_query() 使用复杂的数组

<?php  $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‘<br>),‘CEO‘);  echo http_build_query($data, ‘flags_‘);  /* 输出:(为了可读性对其进行了折行) ??????user[name]=Bob+Smith&user[age]=47&user[sex]=M&user[dob]=5%1F12%1F1956& ??????pastimes[0]=golf&pastimes[1]=opera&pastimes[2]=poker&pastimes[3]=rap& ??????children[bobby][age]=12&children[bobby][sex]=M&children[sally][age]=8& ??????children[sally][sex]=F&flags_0=CEO ???  注意:只有基础数组中的数字下标元素“CEO”才获取了前缀,其它数字下标元素(如 ???  pastimes 下的元素)则不需要为了合法的变量名而加上前缀。  */?>

4.http_build_query()使用对象

<?php ???class myClass { ??????var $foo; ??????var $baz; ??????function myClass() { ???????????$this->foo = ‘bar‘; ???????????$this->baz = ‘boom‘; ??????} ???} ???$data = new myClass(); ???echo http_build_query($data); ???/* 输出:foo=bar&baz=boom*/?> ?????

http_build_query 字符串拼接

原文地址:https://www.cnblogs.com/tine/p/8461203.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved