首页 > 语言 > PHP > 正文

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

2024-05-04 23:52:54
字体:
来源:转载
供稿:网友

本文主要介绍的是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教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选