zoukankan      html  css  js  c++  java
  • http_build_query

    http_build_query -- 生成 url-encoded 之后的请求字符串

    描述

    string http_build_query ( array formdata [, string numeric_prefix])
    根据数组产生一个urlencode之后的请求字符串,如果在基础数组中使用了数字下标同时给出了 numeric_prefix 参数。
    <?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
    ?> 
     
    <?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

    ?> 
     
    <?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 下的元素)则不需要为了合法的变量名而加上前缀。
    ?>  
     
    <?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

    ?> 
  • 相关阅读:
    20155339 Exp9 Web安全基础
    20155339 Exp8 Web基础
    20155339 Exp7 网络欺诈防范
    20155339 Exp6 信息搜集与漏洞扫描
    20155339 Exp5 MSF基础应用
    20155339 Exp4 恶意代码分析
    20155339 Exp3 免杀原理与实践
    20155339平措卓玛 Exp2 后门原理与实践
    20155339平措卓玛 Exp1 PC平台逆向破解(5)M
    20155339 第16周课堂实践加分作业
  • 原文地址:https://www.cnblogs.com/ymj0906/p/3103575.html
Copyright © 2011-2022 走看看