<?php
define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
?>
add a note User Contributed Notes
常量
tom dot harris at home dot com
To get a full path (the equivalent of something like "__PATH__") use
dirname($SCRIPT_FILENAME)
to get the directory name of the called script and
dirname(__FILE__)
to get the directory name of the include file.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Define a case-insensitive constant:
<?php
define("GREETING","Hello you! How are you today?",TRUE);
echo constant("greeting");
?>
The output of the code above will be:
Hello you! How are you today?作者: tzlink 时间: 2007-9-30 14:26
PHP常量使用技巧