php使用函数pathinfo()、parse_url()和basename()解析URL

原创 2016-12-23 09:54:18 396
摘要:本文主要介绍的是php使用函数pathinfo() 、parse_url()和basename()解析URL的实例代码,下面话不多说,直接来看代码实例代码如下:1、利用pathinfo解析URL<?  $test = pathinfo("http://localhost/index.php");  print_r($tes

本文主要介绍的是php使用函数pathinfo() 、parse_url()和basename()解析URL的实例代码,下面话不多说,直接来看代码

实例代码如下:

1、利用pathinfo解析URL

<?
 $test = pathinfo("http://localhost/index.php");
 print_r($test);
?>

结果如下

Array
(
 [dirname] => http://localhost //url的路径
 [basename] => index.php //完整文件名
 [extension] => php //文件名后缀
 [filename] => index //文件名
)

2、利用parse_url()函数解析

<?
 $test = parse_url("http://localhost/index.php?name=tank&sex=1#top");
 print_r($test);
?>

结果如下

Array
(
 [scheme] => http //使用什么协议
 [host] => localhost //主机名
 [path] => /index.php //路径
 [query] => name=tank&sex=1 // 所传的参数
 [fragment] => top //后面根的锚点
)

3、使用basename()解析

<?
 $test = basename("http://localhost/index.php?name=tank&sex=1#top");
 echo $test;
?>

结果如下

index.php?name=tank&sex=1#top

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。

更多关于php使用函数pathinfo()、parse_url()和basename()解析URL请关注PHP中文网(www.php.cn)其它文章!

发布手记

热门词条