构造一个链接,包含键值对 1. [代码] [PHP]代码 ?php /** * 构建查询字符串 */ $vars = array('name' = 'this is a name', 'color' = 'red', 'favorite_punctuation' = '#'); $query_str = http_build_query($vars); $url = '/test/te
1. [代码][PHP]代码
<?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&color=red&favorite_punctuation=%23 ~ ~