Blogger Information
Blog 87
fans 0
comment 0
visits 59214
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第七章:文件路径的解析
黄忠倚的博客
Original
764 people have browsed it

实例

<?php
//分解文件名

//系统常量,魔术常量:__FILE__
echo __FILE__;
// D:\myphp__www\PHPTutorial\WWW\0419\demo4.php

//1.获取文件名
echo '文件名:',basename(__FILE__),'<br>';

//2.获取目录名
echo '目录名是:',dirname(__FILE__),'<br>';

//3.pathinfo()将文件名,目录名,扩展名解析到一个数组中
$pathinfo = pathinfo(__FILE__);
echo '文件名是:',$pathinfo['basename'],'<br>';
echo '文件名是:',$pathinfo['dirname'],'<br>';
echo '文件名是:',$pathinfo['extension'],'<br>';
echo '<hr>';
$pathinfo['dirname'].'/'.$pathinfo['basename'].'<br>';
$pathinfo['dirname'].'\\'.$pathinfo['basename'].'<br>';

//在windows 与linux或unix 上的目录分隔符是不同的
//DIRECTORY__SEPARATOR 注意:SEPARATOR中的有两个A
echo $pathinfo['dirname'].DIRECTORY_SEPARATOR.$pathinfo['basename'].'<br>';
//dirname(__FILE__)

//php5.3+ __DIR__

echo __DIR__,'<br>';
var_dump(dirname(__FILE__)==__DIR__);

// __DIR__;

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post