$url = 'http://www.xxx.com/a/b/c.php';
$arr = pathinfo($url);
print_r($arr);
//输出:
Array |
| ( |
| [dirname] => http://www.xxx.com/a/b //url的路径 |
| [basename] => c.php //完整文件名 |
| [extension] => php //文件名后缀 |
| [filename] => c //文件名 |
| ) |
$url = 'http://www.xxx.com/a/b/c.php?id=1&name="hai"#g';
$arr = parse_url($url);
print_r($arr);
//输出:
Array |
| ( |
| [scheme] => http //使用什么协议 |
| [host] => www.xxx.com //主机名 |
| [path] => /a/b/c.php //路径 |
| [query] => id=1&name="hai"// 所传的参数 |
| [fragment] => g //后面根的锚点 |
| ) |
$url = 'http://www.xxx.com/a/b/c.php?id=1&name="hai"#g';
$arr = parse_url($url);
$arr1 = $arr['path'];
$arr2 = pathinfo($arr1);
print_r($arr2);
//输出:
Array |
| ( |
| [dirname] => /a/b |
| [basename] => c.php |
| [extension] => php |
| [filename] => c |
| ) |
|
$url = 'http://www.xxx.com/a/b/c.php?id=1';
$arr = pathinfo($url);
print_r($arr);
//输出:
Array |
| ( |
| [dirname] => http://www.xxx.com/a/b |
| [basename] => c.php?id=1 |
| [extension] => php?id=1 |
| [filename] => c |
| ) |
|