首页 > 代码库 > PHP URL 与数组的转化

PHP URL 与数组的转化

$array =array ( ‘id‘ =123, ‘name‘ = ‘dopost‘ );echo http_build_query( $array );//得到结果id=123name=dopost

  

举例子如下: 复制代码 代码如下:$url = "http://www.electrictoolbox.com/php-extract-domain-from-full-url/"; $parts = parse_url($url); 输出: 复制代码 代码如下:Array ( [scheme] => http [host] => www.electrictoolbox.com [path] => /php-extract-domain-from-full-url/ ) 又如: 复制代码 代码如下:<?php $url = ‘http://username:password@hostname/path?arg=value#anchor‘; print_r(parse_url($url)); echo parse_url($url, PHP_URL_PATH); ?> 输出: 复制代码 代码如下:Array ( [scheme] => http [host] => hostname [user] => username [pass] => password [path] => /path [query] => arg=value [fragment] => anchor ) 

  本文转载

PHP URL 与数组的转化