语法:
[PHP] 纯文本查看 复制代码 define(name,value,case_insensitive) name 必需。规定常量的名称。
value 必需。规定常量的值。
case_insensitive 必需。规定常量的名称是否对大小写敏感。若设置为 true,则对大小写不敏感。默认是 false(大小写敏感)。
实例一:定义一个大小写的常量:
[PHP] 纯文本查看 复制代码 <?php
define("GREETING","Hello world!");
echo constant("GREETING");
?>
运行输出:
实例二::
[PHP] 纯文本查看 复制代码
define("_INSTALL_DIR","C:\\Program Files\\DDNS Client");
define("_LOGFILE",_INSTALL_DIR . "\\messages.log.txt");
define("_PHP_ERROR_LOG",_INSTALL_DIR . "\\bin\\php-error.log");
define("_PID_FILE",_INSTALL_DIR . "\\bin\\ddns_client.pid");
define("_CONFIGFILE",_INSTALL_DIR . "\\config.ini");
define("_SERVICENAME", "DDNSClient");
define("_SERVICEINFONAME", "DDNSClient");
define("_PATH", _INSTALL_DIR . "\\bin\\php.exe");
define("_PARAMS", "-c \""._INSTALL_DIR."\\bin\\php.ini\" \""._INSTALL_DIR."\\bin\\ddns_client.php\" run");
define("_SLEEP", 130);
第 1 行,定义 _INSTALL_DIR 这个常量的值为一目录: C:\\Program Files\\DDNS Client 。
第 2 行,定义 _LOGFILE 这个常量的值为“C:\\Program Files\\DDNS Client\\bin\\php.exe" ,它表示的是可执行文件 php.exe 的绝对路径。
有第 2 行可见,在 define() 里,还可以用到其它已定义的常量。 |