PHP built-in variable directory_separator detailed

Source: Internet
Author: User
PHP's built-in variable directory_separator is a command that displays the system delimiter, Directory_separator is the internal constant of PHP, and does not require any definition or inclusion to be used directly. This variable is used to solve the file delimiter, on Windows we habitually use \ as a file delimiter, but on the Linux people do not know this logo, people only know/, so we will introduce the following PHP built-in variables: directory_separator

For example:

Define (' Blogguy. Cn_root ', DirName (__file__). " /upload ");

The above definition in the Windows system debugging should be normal, but upload to the Linux server you will find error, the error appears on this file delimiter, so the above can be rewritten as the following the correct wording:

Define (' Blogguy. Cn_root ', DirName (__file__). Directory_separator. " Upload ");

This ensures that there are no errors. For example Discuz is written in this way: define (' S_root ', DirName (__file__). Directory_separator); Back to the problem itself, Directory_separator is a PHP built-in command that returns the path delimiter associated with the operating system, returns \ on Windows, and returns on Linux or Unix-like. This is the difference, which is usually used when defining a file path or uploading a saved directory.

Take a look at the following example:

Const DIR_SEP = directory_separator;//path split under win \ linux/

Private Function __construct () {
$this->_options = Array (
' Template_dir ' = ' templates '. Self::D ir_sep,//directory where template files are located
' Cache_dir ' = ' templates '. Self::D ir_sep. ' Cache '. Self::D ir_sep,//cache file storage Directory
' Auto_update ' = false,//if the cache is regenerated when the template file changes
' Cache_lifetime ' = 0,//Cache life cycle (minutes), 0 for permanent
' Suffix ' = '. html ',//template file suffix
);
}
  • Related Article

    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.