Php backslash/

Source: Internet
Author: User
Some people like to add a slash, for example, $ dir = dirname (_ FILE __). '/'; while some people are too troublesome and the code is not beautiful, use $ dir = dirname (_ FILE __); in this way, problems may occur when we want to include files. For example, to include test. php, if it is dirname (_ FILE _). '/tes

Some people like to add a slash, for example, $ dir = dirname (_ FILE __).'/';
Some people are too troublesome and the code is not beautiful. use $ dir = dirname (_ FILE _) directly __);

In this way, problems may occur when we want to include files.
For example, to include test. php, if it is dirname (_ FILE __). '/test. php ', of course, no problem. if there is no slash, such as dirname (_ FILE __). 'test. php ', then the problem is coming. for D: \ web \ test. php becomes D: \ webtest. php.

Solution:
Directory constants or variables are replaced/
For example:
Include 'd:/web./test. php ';
Include 'd:/web/./test. php ';
Are equivalent
Include 'd:/web/test. php ';

In this way, you do not need to consider whether/is added after the directory name, and the display will be more intuitive when the directory is obtained using constants or variables.
For example:
Define ('root _ path', dirname (_ FILE __).'/');
Include ROOT_PATH. './test. php ';
Ratio
Include ROOT_PATH. '/test. php ';
Include ROOT_PATH. 'test. php ';
It is easier to intuitively determine that the file is under ROOT_PATH.

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.