php的http

來源:互聯網
上載者:User

標籤:img   div   索引值   可讀性   分享   cow   class   注意   擷取   

http_build_query產生 url-encoded 之後的請求字串

 

1、使用索引值對,關聯陣列:

<?php$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*/?> 

2、使用數字下標

<?php$data = array(‘foo‘, ‘bar‘, ‘baz‘, ‘boom‘, ‘cow‘ => ‘milk‘, ‘php‘ =>‘hypertext processor‘);              echo http_build_query($data);/* 輸出:      0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor*/echo http_build_query($data, ‘myvar_‘);/* 輸出:      myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor*/?> 

 3、使用多維陣列:

<?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‘)),              ‘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、使用對象

<?phpclass 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*/?> 

 

php的http

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.