Php built-in variable DIRECTORY_SEPARATOR

Source: Internet
Author: User
Tags file separator
Php's built-in variable DIRECTORY_SEPARATOR is a command for displaying system delimiters. DIRECTORY_SEPARATOR is an internal constant of php and can be directly used without any definition or inclusion. This variable is used to solve file delimiters. on windows, we use it as file delimiters, but on linux, people do not know this identifier, so we need to introduce the following php built-in variable: DIRECTORY_SEPARATOR for example: def php's built-in variable DIRECTORY_SEPARATOR is a command to display system separators. DIRECTORY_SEPARATOR is the internal constant of php, you can use it directly without any definition or inclusion. This variable is used to solve the File Separator. on windows, we habitually use \ as the file separator, but on linux, people do not know this identifier /, so we need to introduce the following php built-in variable: DIRECTORY_SEPARATOR

For example:

define('BLOGGUY.CN_ROOT', dirname(__FILE__)."/upload");

The above definition should be normal for debugging in windows, but when you upload the file to a linux server, you will find an error, and the error will appear on the file separator, therefore, the preceding statement can be rewritten as follows:

define('BLOGGUY.CN_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR."upload");

In this way, the error will not occur. For example, define ('s _ root', dirname (_ FILE _) is written in discuz __). return to the problem itself. DIRECTORY_SEPARATOR is a php built-in command that returns the path separator related to the operating system, returns \ on windows, and returns/on linux or unix-like /, this is the difference. it is usually used when defining the path containing files or uploading and storing directories.

Take a look at the following example:

Const DIR_SEP = DIRECTORY_SEPARATOR; // path separation under win \ linux/

Private function _ construct (){
$ This-> _ options = array (
'Template _ dir' => 'templates'. self: DIR_SEP, // Directory of the template file
'Cache _ dir' => 'templates'. self: DIR_SEP. 'cache'. self: DIR_SEP, // cache file storage directory
'Auto _ update' => false, // whether to regenerate the cache when the template file is changed
'Cache _ lifetime' => 0, // cache lifecycle (minutes), 0 indicates permanent
'Suffix '=> '.html', // template file suffix
);
}

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.