Detailed PHP dirname () function get file information usage

Source: Internet
Author: User
What is the function of PHP dirname ()?

The PHP dirname () function is the part of the directory that returns the file path. It gives a string containing a full path to a file, returning the name of the directory after removing the file name. The syntax is as follows

Grammar:

String DirName (String $path)

Detailed parameters:

The parameter path is a path, which is the path we need to check.

PS: In Windows, slashes (/) and backslashes (\) can be used as directory separators. In other environments it is a slash (/).

The return value of the PHP dirname () function

Returns the parent directory of path. If there is no slash in Path, a point ('. ') is returned. ), which represents the current directory. Otherwise, the string that/component the end of Path (the last slash and later) is removed.

Example

Example One

<?phpecho dirname ("c:/testweb/home.php"). "<br/>"; Echo dirname ("/testweb/home.php");? >

Code Run Result:

Example Two

Suppose there is now a path to the file under the D:/www/images/1.jpg path: We use the PHP dirname () function to get the directory portion of this file, the code is as follows:

<?php$apth= ' d:/www/images/1.jpg '; echo dirname ($apth). "<br/>"; Echo dirname ("/www/images/home.php");? >

The results of the code run as

"Related articles recommended":

Detailed PHP pathinfo () function get file path information

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.