转换PHP数组为查询字符串放到URL中
$data = array( 'apikey'=>'xg6tr7k', 'user'=>'abcd', 'email'=>'root@example.com' ); echo http_build_query($data);
输出:
apikey=xg6tr7k&user=abcd&email=root%40example.com
类似的,PHP也提供解析URL的函数
$query_string ="http://www.A.com/index.php?apikey=xg6tr7k&user=abcd&email=jhon.php%40example.com"; $parsed_url = parse_url($query_string); print_r($parsed_url);
输出:
Array ( [scheme] => http [host] => www.A.com [path] => /index.php [query] => apikey=xg6tr7k&user=abcd&email=jhon.php%40example.com )
注意:使用parse_url()传入的参数中要带有协议名称,类似'http://',这样才是完整的url