php 使用pathinfo(), parse_url(), basename()解析URL

来源:互联网 发布:win10输入法切换软件 编辑:程序博客网 时间:2024/05/29 09:36

原文链接:点击打开链接

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




阅读全文
0 0
原创粉丝点击