This article introduces in detail about PHP dirname, basename, pathinfo parsing directory path, there is a need to learn friends can refer to.
1:string basename (string path[,string suffix]);
Give a string containing a full path to a file, this function returns the base file name. If the file name ends in suffix, then this part will be removed as well.
In Windows, slashes (/) and backslashes () can be used as path separators. In other environments it is a slash (/).
Example 1.basename () example, the code is as follows
<?php$path= Web Authoring Tutorial http://www.bKjia.c0m, please keep this tag "/home/httpd/html/index.php"; $file =basename ($path); $fileissetto "index.php" $file =basename ($path, ". php");//$fileissetto "index"?>
parameter is a string that is a file path, returning the directory after removing the filename
2:string dirname (string path);
__file__ path is the file where the current code resides
DirName (DirName (__file__)); Get the file on the top of the directory name
DirName (__file__); Gets the directory name of the file.
example, the code is as follows
<?phpecho dirname ("c:/testweb/home.php"); Echo dirname ("/testweb/home.php"); >
Output:
C:/testweb/testweb
parameter is a string of file paths that returns an array of three parts containing the directory name, file name, and extension, respectively, by DirName, basename, extension to refer to 3:array pathinfo ($path);
Example 1
<?phpprint_r (PathInfo ("/testweb/test.txt"));? >
Output Result:
Array ([dirname] =/testweb[basename] = test.txt[extension] = txt)
Example 2
<?phpprint_r (PathInfo ("/testweb/test.txt", Pathinfo_basename));? >
Output Result:
Test.txt