php define() º¯Êý¼°defined£¨£©º¯ÊýµÄÓ÷¨
The define() function defines a constant.
define()º¯ÊýµÄ×÷ÓÃÊÇ£º¶¨ÒåÒ»¸ö³£Á¿¡£
Constants are much like variables, except for the following differences:
³£Á¿[constant]Óë±äÁ¿[variable]ÓкܶàÏàËÆµÄµØ·½£¬Òò´Ë£¬ºÜÈÝÒ×»ìÏý£»ÏÂÃæ£¬ÎÒÃÇÁоÙһϳ£Á¿[constant]Óë±äÁ¿[variable]Ö®¼äµÄ²»Í¬µã£º
A constant's value cannot be changed after it is set
Ò»¸ö³£Á¿ÖµÔÚÖ¸¶¨Ö®ºó¾Í²»¿ÉÒÔ¸ü¸Ä£»
Constant names do not need a leading dollar sign ($)
ÉèÖó£Á¿Ê±£¬²»ÐèÒªÔÚÇ°Ãæ¼ÓÉÏ“$”·ûºÅ£»
Constants can be accessed regardless of scope
³£Á¿¿ÉÒÔ±»ËùÓз¶Î§µÄÓò·ÃÎÊ£»
Constant values can only be strings and numbers
³£Á¿µÄÖµÖ»ÄÜÊÇ“×Ö·û´®[string]”ºÍ“Êý×Ö[number]”£»
Syntax
Óï·¨
define(name,value,case_insensitive)
Parameter
²ÎÊýDescription
ÃèÊö
name
Required. Specifies the name of the constant
±ØÒª²ÎÊý¡£Ö¸¶¨³£Á¿µÄÃû³Æ
value
Required. Specifies the value of the constant
±ØÒª²ÎÊý¡£Ö¸¶¨³£Á¿µÄÖµ
case_insensitive
Optional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant will be case-insensitive. Default is FALSE (case-sensitive)
¿ÉÑ¡²ÎÊý¡£Ö¸¶¨³£Á¿µÄÃû³ÆÊÇ·ñÊDz»Çø·Ö´óСдµÄ[case-insensitive]¡£Èç¹ûÉèÖÃΪTrue£¬Ôò²»Çø·Ö×Öĸ´óСд£»Èç¹ûÉèÖÃΪFalse£¬ÔòÇø·Ö×Öĸ´óСд¡£Ä¬ÈÏÖµÊÇ£ºFalse
Example 1
°¸Àý1
Define a case-sensitive constant:
Ö¸¶¨Ò»¸ö³£Á¿£¨Çø·Ö´óСд£©£º
<?phpdefine("GREETING","Hello you! How are you today?");echo constant("GREETING");?>
The output of the code above will be:
ÉÏÊö´úÂ뽫Êä³öÏÂÃæµÄ½á¹û£º
Hello you! How are you today?
Example 2
°¸Àý2
Define a case-insensitive constant:
Ö¸¶¨Ò»¸ö³£Á¿£¨²»Çø·Ö´óСд£©£º
<?phpdefine("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?
The defined() function checks whether a constant exists.
defined()º¯ÊýµÄ×÷ÓÃÊÇ£º¼ì²éÒ»¸ö³£Á¿ÊÇ·ñ´æÔÚ¡£
Returns TRUE if the constant exists, or FALSE otherwise.
Èç¹û¸Ã³
Ïà¹ØÎĵµ£º
Óõ¥ÒýºÅ´úÌæË«ÒýºÅÀ´°üº¬×Ö·û´®£¬ÕâÑù×ö»á¸ü¿ìһЩ¡£ÒòΪPHP»áÔÚË«ÒýºÅ°üΧµÄ×Ö·û´®ÖÐËÑѰ±äÁ¿£¬µ¥ÒýºÅÔò²»»á£¬×¢Ò⣺ֻÓÐechoÄÜÕâô×ö£¬ËüÊÇÒ»ÖÖ¿ÉÒ԰Ѷà¸ö×Ö·û´®µ±×÷²ÎÊýµÄ“º¯Êý”£¨Òë×¢£ºPHPÊÖ²áÖÐ˵echoÊÇÓïÑԽṹ£¬²»ÊÇÕæÕýµÄº¯Êý£¬¹Ê°Ñº¯Êý¼ÓÉÏÁËË«ÒýºÅ£©¡£
1¡¢Èç¹ûÄܽ«ÀàµÄ·½·¨¶¨Òå³Éstatic£¬¾Í¾¡Á¿¶¨Ò ......
phpÏÂÔØ£º
http://windows.php.net/download/
Ñ¡Ôñ
VC6 x86 Thread Safe (2010-Mar-04 20:11:08)
VC6 x86´ú±í Apache HTTP Server (httpd) 2.2.15 ºÍPHP½áºÏ
apacheÏÂÔØ£º
http://httpd.apache.org/download.cgi#apache22
Ñ¡Ôñ2.2.15
httpd-2.2.15-win32-x86-no_ssl.msi [PGP] [MD5] [SHA1]
apache services 2.2Ð ......
Ö®Ç°ÍøÒ³µÄchartsetÓõÄÊÇutf-8£¬ÎļþÒ²ÓÃutf-8£¬È»ºóÓÃfopen()´´½¨Ò»¸öÖÐÎÄÎļþÃûµÄÎļþʱÎÊÌâ¾Í³öÀ´ÁË£¬ÎļþÃû¶¼ÊÇÂÒ
Â룡
²é¿´Á˺ܶàÎĵµÊÔÁ˲»ÉÙ·½·¨¶¼½â¾ö²»ÁË£¬±¾À´Ïë×ÅÓñðµÄ·½·¨ÈƹýÕâ¸öÎÊÌ⣬ºöÈ»ÄÔ×ÓÀïÉÁ¹ýWindowsĬÈϵÄÎÄ×Ö±àÂëÊÇansi£¬È»ºóÔÙ
baiduÁËһϣ¬Ö¤ÊµÁËÕâµã£¬ËùÒÔÎÒµÄÍøÒ³Ò²Ó¦¸ÃÊÇansi±àÂë²ÅÄÜʹ´ ......
<?php
@mysql_connect("localhost", "root","1981427") //Ñ¡ÔñÊý¾Ý¿â֮ǰÐèÒªÏÈÁ¬½ÓÊý¾Ý¿â·þÎñÆ÷
or die("Êý¾Ý¿â·þÎñÆ÷Á¬½Óʧ°Ü");
$dbs = mysql_list_dbs(); //µ÷ÓÃmysql_list_dbsº¯Êý
while ($array = mysql_fetch_row($dbs)) //Ñ»·Êä³öËùÓеÄÊý¾Ý¿âÃû³Æ
{
echo "$array[0]<BR>";
}
?>
& ......