1.basename ()-Returns the file name of the path
Take a look at the following PHP code:
1<?PHP2 3 $path= "/usr/www/html/index.php";4 5 Echo basename($path)." <br> ";6 7 //If you select suffix, the extension is ignored8 9 Echo basename($path, ". PHP");Ten One?>
Operation Result:
index.php
Index
2.dirname ()-Returns the file path of the current script!
PHP Code:
- <? PHP
- --file__ return file Full path
- $dir = dirname(__file__);
- echo $dir;
- ?>
Operation Result:
F:\web\zend\exercise
3.pathinfo () returns an associative array containing information about path.
Includes the following array cells: path name dirname, file name basename, and extension name extension.
Take a look at the following simple code demo:
- <? PHP
- $path = "/usr/www/html/index.php";
- $pathinfo = pathinfo($path);
- echo "Catalog name: $pathinfo [dirname]<br>";
- echo "file name: $pathinfo [basename]<br>";
- echo "extension: $pathinfo [extension]";
- ?>
Operation Result:
Catalog Name:/usr/www/html
File name: index.php
Extension: PHP
4.realpath--Returns the normalized absolute path name
The PHP code is as follows:
- <? PHP
- $path = "./exercise/php.txt";
- $realpath = realpath($path);
- echo $realpath;
- ?>
Finally note a tip: Different paths of File path operators may, different, Windows can use "/" and "\",
Linux can only use "/", so the development of the time, the recommendations are used "/", such as my file path above the wording!
PHP gets the file name and extension