Home  >  Article  >  php教程  >  Build query string

Build query string

WBOY
WBOYOriginal
2016-08-18 08:57:541258browse
跳至 [1] [全屏预览]
  <?php
  /**
   * 构建查询字符串
   */
   
  $vars = array('name' => 'this is a name',
                'color' => 'red',
                'favorite_punctuation' => '#');
  $query_str = http_build_query($vars);
  
  $url = '/test/test.php?' . $query_str;
  echo $url."\n";
  
  $url = '/test/test.php?' . htmlentities($query_str);
  echo $url."\n";

输出结果:
/test/test.php?name=this+is+a+name&color=red&favorite_punctuation=%23
/test/test.php?name=this+is+a+name&amp;color=red&amp;favorite_punctuation=%23


~                                                                                                                                                                                                           
~                    
Statement:
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
Previous article:Zero basic programmingNext article:Zero basic programming