<?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 ~ ~