PHP
·
发表于 5年以前
·
阅读量:8312
WEBµÄÓ¦ÓÃ
µ±¿Í»§¶ËÏoþÎñÆ÷µÄ³ÌÐoÌa³oÇeÇoʱ£¬webþÎñÆ÷¸u¾ÝÇeÇoÏiÓ¦¶ÔÓ¦µÄÒ³Ãae£¬µ±Ò³ÃaeÖк¬ÓÐPHP½Å±¾Ê±£¬*þÎñÆ÷»a½»¸øPHP½aÊÍÆ÷½øÐнaÊÍÖ´ÐУ¬½«Éu³ÉµÄhtml´uÂeÔٻش«¸ø¿Í»§¶Ë£¬¿Í»§¶ËµÄa¯ÀÀÆ÷½aÊÍhtml´uÂe£¬×iÖÕÐγÉÍøÒ³¸ñʽµÄÒ³Ãae¡£
PHPÄÜ×oʲô
PHPÖ÷ÒªÓ¦ÓÃÓÚÈý¸oÁiÓo£º
PHPÖÎoÆ÷£¬Ò»¸oWEBþÎñÆ÷Æ÷ºÍÒ»¸oWEBa¯ÀÀÆ÷¡£
PHPÓi*¨½a¹¹
±a³ÌÓiÑԵĴʨ½a¹¹£¨lexical structure£(C)ÊÇÖ¸¹ÜÀiÈçºÎÓÃÓiÑÔд³ÌÐoµÄ»u±¾¹aeÔoµÄ¼¯ºÏ¡£
Óû§×Ô¶¨ÒaµÄº¯ÊýÃu»oÀaÃu¶¼ÊDz»ÇøÖ´oСдµÄ£¬±aÁ¿ÇøÖ´oСд¡£Õa¾ÍÊÇ˵£¬$name ¡¢$NAME ºÍ$NaMeÊÇÈý¸o²»Í¬µÄ±aÁ¿¡£
PHPÓÃÖºÅÀ´*Ö¸o¼oµ¥µÄÓi¾a¡£
PHP×¢ÊÍ
PHPÖ§³ÖC¡¢C£«£«ºÍShell½Å±¾ç¸ñµÄ×¢ÊÍ£¬ÈçÏ£º
// µ¥ÐÐ×¢ÊÍ
/ */ ¶aÐÐ×¢ÊÍ £¨×¢Òa£º²»ÄÜǶÌ×£(C)
³£Á¿
³£Á¿ÊÇÒ»¸o¹Ì¶¨ÊýÖµ£¬ÓÃÒ»¸o¼oµ¥µÄ±eʶ*u½øÐж¨Òa£¬³£Á¿Ä¬ÈÏΪ´oСдÃo¸Ð¡£
°´ÕÕ¹ßÀý³£Á¿±eʶ*u×ÜÊÇ´oдµÄ¡£
define()ÓÃÕa¸oº¯ÊýÀ´¶¨Òa³£Á¿¡£
string(×Ö*u´®)³£Á¿*ÖΪ£ºÄÚÖó£Á¿ºÍ×Ô¶¨Òa³£Á¿¡£
³£ÊýÖ»ÄÜ°uº¬±eÁ¿Êý¾Ý£¨boolean(²¼¶u)£¬integer(ÕuÐÎ)£¬float(¸¡µaÊý)£(C)
ÄÚÖó£Á¿£ºPHPϵͳÌa¹(C)µÄÔÚÈκÎÒ³ÃaeÊýÖµ²»»a¸Ä±aµÄ³£Á¿
PHP_OS:ÏÔʾ*þÎñÆ÷µÄ²Ù×÷ϵͳ°ae±¾
PHP_VERSION:ÏÔʾPHP°ae±¾
Ò»Ð(C)³£¼uµÄϵͳ³£Á¿
__FILE__:PHPÎļþÃu,¼ÙÈçÊÇÒýÓÃÎļþ,ÔoÏÔʾÒýÓÃÎļþÃu
__LINE__:PHPÎļþµÄÐÐÊý
TRUE FALSE:±iʾÕae¼ÙµÄ³£Á¿
E_ERROR:Ö¸Ã÷ÁË´uÂeÖÐ×i½uµÄ´iÎo´¦
E_WARNING:Ö¸Ã÷ÁË´uÂeÖÐ×i½uµÄ¾¯¸ae´¦
E_PARSE:*ÖÎo´uÂeºÎ´¦ÓÐ×ÅDZÔÚµÄÎÊÌa
E_NOTICE:Ϊ*¢Éu²»Ñ°³£µ«²»Ò»¶¨ÊÇ´iÎoµÄµØ*½
×Ô¶¨Òa³£Á¿
ÓÃdefine()À´¶¨Òa³£Á¿
define(¡°mycomputer¡±, ¡°IBM¡±);
¶¨Òa³£Á¿£ºmycomputer ³£Á¿µÄֵΪ IBM
defined(¡°mycomputer¡±);
¼i²a³£Á¿ÊÇ*ñ±»¶¨Òa£¬ÒѶ¨Òa*µ»Ø1 *ñÔo*µ»Ø¿Õ
±aÁ¿
PHP ÖÐÒ»¸oÃÀÔª*uºÅ£¨$£(C)ºoÃae¸uÉÏÒ»¸o±aÁ¿Ãu³Æ£¬¼´±iʾһ¸o±aÁ¿¡£±aÁ¿µÄÃu³ÆÊǶԴoСдÃo¸ÐµÄ
< php
$var = ¡®Bob';
$Var = ¡®Joe';
echo ¡°$var, $Var¡±; // Êa³o ¡°Bob, Joe¡± ¿ÉÒÔͬʱÊa³oÁ½¸o±aÁ¿Ãu
$4site = ¡®not yet'; // *Ç*¨±aÁ¿Ãu£»ÒÔÊý×Ö¿ªÍ* ±aÁ¿²»ÄÜÒÔÊý×Ö¿ªÍ*
$_4site = ¡®not yet'; // ºÏ*¨±aÁ¿Ãu£»ÒÔÏ»®Ïß¿ªÍ* ¿ÉÒÔÒÔÏ»®Ïß¿ªÍ*
$iÕ¾µais = ¡®mansikka'; // ºÏ*¨±aÁ¿Ãu£» ¿ÉÒÔÓÃÖÐÎÄ µ«ÊDz»½¨ÒeʹÓÃ
isset($var) //¼i²e±aÁ¿ÊÇ*ñ¶¨Òa
unset($var) //ɾ³ý±aÁ¿$var
empty($var) //ÅжÏÒ»¸o±aÁ¿µÄÖµÊÇ*ñ´aeÔÚ
echo $var //¿Õ
>
¿É±a±aÁ¿
Ò»¸o¿É±a±aÁ¿»ñÈ¡ÁËÒ»¸oÆÕͨ±aÁ¿µÄÖµ×÷ΪÕa¸o¿É±a±aÁ¿µÄ±aÁ¿Ãu
< php
$a = 'hello'; //ÆÕͨ±aÁ¿
$$a = 'world'; //¿É±a±aÁ¿ ¿É±a±aÁ¿ÓÃÒ»¸oÆÕͨ±aÁ¿µÄÖµ×÷Ϊ¿É±a±aÁ¿µÄÃu
echo "$a ${$a}"; //Êa³o£ºhello world
echo "$a $hello"; //Êa³o£ºhello world
>
³£Á¿ºÍ±aÁ¿²»Í¬
³£Á¿Ç°ÃaeûÓÐÃÀÔª*uºÅ£¨$£(C)£»
³£Á¿Ö»ÄÜÓà define( ) º¯Êý¶¨Òa£¬¶ø²»ÄÜͨ¹ý¸³ÖµÓi¾a£»
³£Á¿¿ÉÒÔ²»ÓÃÀi»a±aÁ¿*¶Î§µÄ¹aeÔo¶øÔÚÈκεØ*½¶¨ÒaºÍ*ÃÎÊ£»
³£Á¿Ò»µ(C)¶¨Òa¾Í²»Äܱ»ÖØж¨Òa»oÕßÈ¡Ïu¶¨Òa£»
³£Á¿µÄÖµÖ»ÄÜÊDZeÁ¿
Êý¾ÝÀaÐÍ
ËÄÖÖ±eÁ¿ÀaÐÍ£º
²¼¶uÐÍ£¨boolean£(C)
ÕuÐÍ£¨integer£(C)
¸¡µaÐÍ£¨float£(C)£¨¸¡µaÊý£¬Ò²×÷double£(C)
×Ö*u´®£¨string£(C)
Á½ÖÖ¸´ºÏÀaÐÍ£º
Êý×e£¨array£(C)
¶ÔÏo£¨object£(C)
×iºoÊÇÁ½ÖÖÌØÊaÀaÐÍ£º
×ÊÔ´£¨resource£(C)
NULL ¿Õ
PHPÊÇÒ»ÖÖ*dz£ÈoµÄÀaÐÍÓiÑÔ¡£
ÔÚPHPÖУ¬±aÁ¿µÄÀaÐÍͨ³£²»ÊÇÓɳÌÐoÔ±Ée¶¨µÄ£¬È*ÇеØ˵£¬ÊǸu¾Ý¸Ã±aÁ¿Ê¹ÓõÄÉÏÏÂÎÄÔÚÔËÐÐʱ£¨¼´±aÁ¿µÄÖµ£(C)¾o¶¨µÄ¡£
ʵÀý£º
< php
$bool = TRUE; // ²¼¶uÐÍ
$str = ¡°foo¡±; // ×Ö*u´®
$int = 12; // ÕuÐÍ
echo gettype($bool); // Êa³o boolean £¨gettype»ñÈ¡±aÁ¿µÄÀaÐÍ£(C)
echo gettype($str); // Êa³o string
>
ÕuÐÍ
ÕuÐÍÖµ¿ÉÒÔÓÃÊ®½øÖÆ£¬Ê®Áu½øÖÆ»o°Ë½øÖÆ*uºÅÖ¸¶¨£¬Ç°Ãae¿ÉÒÔ¼ÓÉÏ¿ÉÑ¡µÄ*uºÅ£¨- »oÕß +£(C)¡£
< php
$a = 1234; // Ê®½øÖÆÊý
$a = -123; // Ò»¸o¸ºÊý
$a = 0123; // °Ë½øÖÆÊý£¨µÈÓÚÊ®½øÖÆµÄ 83£(C)
$a = 0x1a; // Ê®Áu½øÖÆÊý£¨µÈÓÚÊ®½øÖÆµÄ 26£(C)
>
¸¡µaÐÍ
¸¡µaÊý£¨Ò²½Ð¸¡µaÊý£¬Ë«¾«¶ÈÊý»oʵÊý£(C)¿ÉÒÔÓÃÒÔÏÂÈκÎÓi*¨¶¨Òa£º
< php
$a = 1.234;
$a = 1.2e3;
$a = 7E-10;
>
×Ö*u´®
stringÊÇһϵÁÐ×Ö*u¡£ÔÚ PHP ÖУ¬×Ö*uºÍ×Ö½ÚÒ»Ñu£¬Ò²¾ÍÊÇ˵£¬Ò»¹²ÓÐ 256 ÖÖ²»Í¬×Ö*uµÄ¿ÉÄÜÐÔ¡£ÕaÒ²°µÊ¾ PHP ¶Ô Unicode ûÓб¾µØÖ§³Ö¡£(¹ØÓÚ×Ö*u´®ÀaÐͺoÃaeרÓÐÒ»ÕÂÏeϸ½²½a)
< php $str = ¡°hello world!¡±; >
²¼¶uÐÍ
ÕaÊÇ×i¼oµ¥µÄÀaÐÍ¡£boolean ±i´iÁËÕaeÖµ£¬¿ÉÒÔΪ TRUE »o FALSE¡£
µ±ÆaËuÀaÐÍת»»Îª booleanÀaÐÍ Ê±£¬ÒÔÏÂÖµ±»ÈÏΪÊÇFALSE£º
²¼¶uÖµ FALSE
ÕuÐÍÖµ 0£¨Áa£(C)
¸¡µaÐÍÖµ 0.0£¨Áa£(C)
¿Õ°××Ö*u´®ºÍ×Ö*u´® "0"
ûÓгÉÔ±±aÁ¿µÄÊý×e
ûÓе¥ÔªµÄ¶ÔÏo£¨½oÊÊÓÃÓÚ PHP 4£(C)
ÌØÊaÀaÐÍ NULL£¨°uÀ¨ÉÐδÉe¶¨µÄ±aÁ¿£(C)
ËuÓÐÆaËuÖµ¶¼±»ÈÏΪÊÇ TRUE£¨°uÀ¨ÈκÎ×ÊÔ´£(C)¡£
Êý×e
Êý×eÊÇPHPÖеÄÒ»ÖÖÖØÒªµÄÊý¾ÝÀaÐÍ¡£Ò»¸o±eÁ¿Ö»ÄÜ´ae*ÅÒ»¸oÊý¾Ý£¬ ¶øÊý×e¿ÉÒÔ´ae*Ŷa¸oÊý¾Ý¡£
$my=array(¡®1',¡®2',¡®abc',¡®d');
¶ÔÏo(Object)
¶ÔÏoÊÇÒ»Öָ߼¶µÄÊý¾ÝÀaÐÍÒÔºo»aѧ
×ÊÔ´(Resource)
×ÊÔ´ÊÇÓÉרÃŵĺ¯ÊýÀ´½¨Á¢ºÍʹÓõÄ
ÀaÐÍÇ¿ÖÆת»»
PHP ÖеÄÀaÐÍÇ¿ÖÆת»»£ºÔÚҪת»»µÄ±aÁ¿Ö®Ç°¼ÓÉÏÓÃÀ¨ºÅÀ¨ÆðÀ´µÄÄ¿±eÀaÐÍ¡£
ÔÊÐiµÄÇ¿ÖÆת»»ÓУº
(int), (integer) - ת»»³ÉÕuÐÍ
(bool), (boolean) ¨C ת»»³É²¼¶uÐÍ
(float), (double), (real) - ת»»³É¸¡µaÐÍ
(string) - ת»»³É×Ö*u´®
(array) - ת»»³ÉÊý×e
(object) ¨C ת»»³É¶ÔÏo
< php
$foo = 10; // $foo is an integer
$bar = (boolean) $foo; // $bar is a boolean
>
µ±Ç°1/2Ò³ **1**2ÏÂÒ»Ò³ÔĶÁÈ«ÎÄ