parse_url 解析url的函数
<?php //PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, //PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT $url = "http://www.baidu.com/abc/ab/1.php?id=1"; $path = parse_url($url,PHP_URL_PATH); $scheme = parse_url($url,PHP_URL_SCHEME); $host = parse_url($url,PHP_URL_HOST); $query = parse_url($url,PHP_URL_QUERY); $fragment = parse_url($url,PHP_URL_FRAGMENT); echo $path; ///abc/ab/1.php echo $scheme; //http echo $host; //www.baidu.com echo $query; //id=1 echo $fragment; // PHP_URL_QUERY 或 PHP_URL_FRAGMENT 的其中一个来获取 URL 中指定的部分的 string。