Home > Backend Development > PHP Tutorial > php函数学习一

php函数学习一

WBOY
Release: 2016-06-13 13:08:33
Original
867 people have browsed it

php函数学习1

1.string dirname(string path)--返回路径中的目录中部分。

例子1:

??? $path="/etc/myMusic";
??? $file=dirname($path);// 变量file为/etc
??? echo $file;??

?>

2.string basename ( string path [, string suffix])--返回路径中的文件名部分

例子1:

??? $path="/etc/myMusic/index.php";

??? $filename=basename($path,'.php');//变量filename为index

??? $filename1=basename($path);//变量filename1为index.php

??? echo $filename;

?>

3.array pathinfo ( string path) --返回文件路径的信息,

pathinfo() 返回一个结合数组包含有 path 的信息。包括以下的数组单元:dirname basename extension

??? $path_parts=pathinfo("/www/htdocs/index.html");
??? echo $path_parts["dirname"] . "
";
??? echo $path_parts["basename"] . "
";
??? echo $path_parts["extension"] . "
";
?>

运行结果:

/www/htdocs
index.html
html

4.string realpath ( string path) --返回规范化的绝对路径

realpath() 扩展所有的符号连接并且处理输入的 path 中的 '/./', '/../' 以及多余的 '/' 并返回规范化后的绝对路径名。返回的路径中没有符号连接,'/./' 或 '/../' 成分。

例子1:

??? $path=realpath("C:\\\..\.\.\\\wamp\.\\\www\\.\.\.\\php\\\\realpath.php");
??? echo $path;
?>

运行结果:

C:\wamp\www\php\realpath.php

?

?

?

?

?

?

?

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template