Home > php教程 > php手册 > body text

PHP5.3中新增的魔术常量

WBOY
Release: 2016-06-06 19:56:21
Original
1118 people have browsed it

来源:PHP5.3中新增的魔术常量__DIR__ 我们知道PHP中提供了一个魔术常量(magic constant) __FILE__,用来指向当前执行的PHP脚本。但PHP没有直接提供该脚本所在目录的常量。也就是说如果我们要得到当前PHP脚本所在的目录,需要使用dirname()这个函数: ?php $

来源:PHP5.3中新增的魔术常量__DIR__

我们知道PHP中提供了一个魔术常量(magic constant)__FILE__,用来指向当前执行的PHP脚本。但PHP没有直接提供该脚本所在目录的常量。也就是说如果我们要得到当前PHP脚本所在的目录,需要使用dirname()这个函数:

$dir = dirname(__FILE__);

?>

在PHP5.3中,增加了一个新的常量__DIR__,指向当前执行的PHP脚本所在的目录。

例如当前执行的PHP文件为 /www/website/index.php

__FILE__等于'/www/website/index.php'

__DIR__等于'/www/website'

现在我们要包含当前文件目录或子目录下的文件,可以直接使用:

require_once __DIR__ . '/path/to/test.inc.php';
?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!