PHP dirname, basename, pathinfo parse directory path

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.