码迷,mamicode.com
首页 > Web开发 > 详细

php常用的路径有关的函数

时间:2015-02-01 17:32:16      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

简单整理一下工作中经常用到的php路径函数

1、basename($path, $suff):返回基本的文件名,如果是以$suff 结束的就去掉

$path = ‘E:\centos\index.php‘;
echo basename($path, ‘.php‘);  // index
echo basename($path);  // index.php

2、dirname($path)返回路径中的目录部分

$url = ‘http://www.baidu.com/abc/index.php?id=1‘;
echo dirname($url); // http://www.baidu.com/abc

3、realpath($path)返回规范化的绝对路径名

$path = ‘../phpinfo.php‘;
echo realpath($path);    // E:\wamp\Apache2.2\htdocs\phpinfo.php

4、pathinfo($path, [int $options])返回文件路径的信息,option 可以指定返回那些单元

$url = ‘http://www.baidu.com/abc/index.php?id=1‘;
$res = pathinfo($url);
echo $res[‘dirname‘];    // http://www.baidu.com/abc
echo $res[‘basename‘]; // index.php?id=1
echo $res[‘extension‘]; // php?id=1
echo $res[‘filename‘]; //  index

5、parse_url($url)解析 URL,返回其组成部分

$url = ‘http://www.baidu.com/abc/index.php?id=1#test‘;
$res = parse_url($url);
echo $res[‘scheme‘];    // http
echo $res[‘host‘];    // www.baidu.com
echo $res[‘path‘];    // /abc/index.php
echo $res[‘query‘];    // 在问号之后的:id=1
echo $res[‘fragment‘];    // 在#之后:test

php常用的路径有关的函数

标签:

原文地址:http://www.cnblogs.com/hanpengyu/p/4265627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!