PHPÈëÃÅËÙ³É(1)

5年以前  |  阅读数:778 次  |  编程语言:PHP 

PHP¼o½e

PHPÊÇÒ»ÖÖÓÃÓÚ´´½¨¶¯Ì¬WEBÒ³ÃaeµÄþÎñ¶Ë½Å±¾ÓiÑÔ¡£ÈçͬASPºÍColdFusion£¬Óû§¿ÉÒÔ»iºÏʹÓÃPHPºÍHTML±aдWEBÒ³Ãae£¬µ±ÃÎÊÕßa¯ÀÀµ½¸ÃÒ³Ãaeʱ£¬þÎñ¶Ë»aÊ×ÏȶÔÒ³ÃaeÖеÄPHPÃuÁi½øÐд¦Ài£¬È»ºo°Ñ´¦ÀiºoµÄ½a¹uÁ¬Í¬HTMLÄÚÈÝÒ»Æð´«Ë͵½ÃÎʶ˵Äa¯ÀÀÆ÷¡£µ«ÊÇÓeASP»oColdFusion²»Í¬£¬PHPÊÇÒ»ÖÖÔ´´uÂe¿ªÅ³ÌÐo£¬ÓµÓкܺõĿçƽ̨¼aeÈÝÐÔ¡£Óû§¿ÉÒÔÔÚWindows NTϵͳÒÔ¼°Ði¶a°ae±¾µÄUnixϵͳÉÏÔËÐÐPHP£¬¶øÇÒ¿ÉÒÔ½«PHP×÷ΪApacheþÎñÆ÷µÄÄÚÖÃÄ£¿e»oCGI³ÌÐoÔËÐС£

³ýÁËÄܹ»¾«ÈµÄ¿ØÖÆWEBÒ³ÃaeµÄÏÔʾÄÚÈÝÖ®Ía£¬Óû§»¹¿ÉÒÔͨ¹ýʹÓÃPHP¢ËÍHTTP±¨Í¡£Óû§¿ÉÒÔͨ¹ýPHPÉeÖÃcookies£¬¹ÜÀiÓû§ÉiÝʶ±ð£¬²¢¶ÔÓû§a¯ÀÀÒ³Ãae½øÐÐÖض¨Ïo¡£PHP¾ßÓÐdz£Ç¿´oµÄÊý¾Ý¿aÖ§³Ö¹¦ÄÜ£¬Äܹ»ÃÎʼ¸ºoÄ¿Ç°ËuÓнÏΪÁ÷ÐеÄÊý¾Ý¿aϵͳ¡£´ËÍa£¬PHP¿ÉÒÔÓe¶a¸oÍa½Ó¿a¼¯³É£¬ÎªÓû§Ìa¹(C)¸u¶aµÄʵÓù¦ÄÜ£¬ÈçÉu³ÉPDFÎļþµÈ¡£

Óû§¿ÉÒÔÖ±½ÓÔÚWEBÒ³ÃaeÖÐÊaÈePHPÃuÁi´uÂe£¬Òo¶ø²»ÐeÒªÈκÎÌØÊaµÄ¿ª¢»¾³¡£ÔÚWEBÒ³ÃaeÖУ¬ËuÓÐPHP´uÂe¶¼±»ÅÖÃÔÚ¡°< ?php¡±ºÍ¡° ? >¡±ÖС£´ËÍa£¬Óû§»¹¿ÉÒÔÑ¡ÔñʹÓÃÖiÈç< SCRIPT LANGUAGE="php" >< /SCRIPT >µÈµÄÐÎʽ¡£PHPÒýÇae»a×Ô¶¯Ê¶±ð²¢´¦ÀiÒ³ÃaeÖÐËuÓÐλÓÚPHP¶¨½çuÖ®¼aµÄ´uÂe¡£

PHP½Å±¾ÓiÑÔµÄÓi¨½a¹¹ÓeCÓiÑÔºÍPerlÓiÑÔµÄÓi¨ç¸ñdz£ÏaËÆ¡£Óû§ÔÚʹÓñaÁ¿Ç°²»ÐeÒª¶Ô±aÁ¿½øÐÐÉuÃ÷¡£Ê¹ÓÃPHP´´½¨Êý×eµÄ¹ý³ÌҲdz£¼oµ¥¡£PHP»¹¾ßÓлu±¾µÄÃaeÏo¶ÔÏo×e¼þ¹¦ÄÜ£¬¿ÉÒÔ¼«´oµÄ½±aÓû§ÓÐЧ×eÖ¯ºÍ*a×°×Ô¼º±aдµÄ´uÂe¡£

PHPÓi*¨¸ÅÊo

A. »u±¾Ói*¨

¼´Ê¹³o´Î½Ó´¥PHPµÄÓû§Ò²»a¢ÏÖ×Ô¼º¶ÔPHPµÄÓi¨*ç¸ñ²¢²»Ä°Éu¡£
ÀýÈ磺

< £¿php

echo ¡°Hello£¡¡±£»

£¿ >

ÏÔʾ½a¹uΪ¡°Hello£¡¡±¡£

PHPÖУ¬ËuÓеıaÁ¿¶¼ÒÔ±eʶ¡°$¡±¿ªÍ*¡£ÎÒÃÇ¿ÉÒÔ¶ÔÉÏÊo´uÂe×oÈçϸĶ¯£º
< £¿php

$greeting = ¡°Hello£¡¡±£»

echo $greeting£»

£¿ >

¸Ä±aºoµÄ´uÂeÏÔʾ½a¹u²»±a¡£
PHPÖÐʹÓá°.¡±uºÅÁ¬½Ó²»Í¬µÄ×Öu´®£¬¶øÆaËuµÄËaÊoÔËËauÔo¼Ì³ÐÁËÁ÷Ðбa³ÌÓiÑÔµÄç¸ñ¡£¾ÙÀýÈçÏ£º

< £¿php

$greeting = ¡°Hello£¡¡±£»

$num = 3 + 2£»

$num++£»

echo ¡°$greeting $num people£¡¡±£»

£¿ >

ÏÔʾ½a¹uΪ¡°Hello£¡6 people£¡¡±¡£

PHP¶Ô¸÷ÖÖÔËËau¼°ÔËËa¹aeÔo¶¼ÓÐÒ»Ì×ÍeÕuµÄ¹ae¶¨£¬Èç¹uÓû§¾ßÓÐC»oC++ÓiÑԵıa³Ì±³¾°µÄ»°£¬¿ÉÒÔ¢ÏÖÒ»Çж¼µÃÐÄÓ¦ÊÖ¡£
ÓePerlÓiÑÔÒ»Ñu£¬ÔÚPHPÖУ¬Èç¹uÔÚË«ÒýºÅ°uº¬µÄ×Öu´®Öк¬ÓбaÁ¿µÄ»°£¬¸Ã±aÁ¿½«ÓÃÏaÓ¦µÄ±aÁ¿ÖµÌae»»£»Èç¹u×Öu´®±»µ¥ÒýºÅ°uº¬£¬Ôo²»×oÌae»»¡£ÀýÈ磺

< £¿php

$name = ¡®PETER'£»
$greeting_1 = ¡°Hello, $name£¡¡±£»
$greeting_2 = ¡®Hello, $name£¡'£»
echo ¡°$greeting_1\n¡±£»
echo ¡°$greeting_2\n¡±£»
£¿ >
ÏÔʾ½a¹uΪ£º
Hello, PETER£¡
Hello, $name£¡
£¨×¢£ºÉÏÊo´uÂeÖеġ°\n¡±Îª»»ÐÐu£¬Ö»ÄÜÔÚË«ÒýºÅ×Öu´®ÏÂʹÓã(C)

B. ±aÁ¿

PHPÔÊÐiÓû§ÏoʹÓó£¹ae±aÁ¿Ò»ÑuʹÓû*¾³±aÁ¿¡£ÀýÈ磬ÔÚÒ³Ãaehttp://www.nba.com/scores/index.htmlÖаuº¬ÈçÏ´uÂe£º

< £¿php

echo ¡°[$REQUEST_URI]¡±£»

£¿ >

ÔoÊa³o½a¹uΪ[/scores/index.html]

C. Êý×e

Óû§ÔÚʹÓÃPHP´´½¨Êý×eʱ£¬¿ÉÒÔ°ÑÊý×eË÷Òý£¨°uÀ¨³£¹aeË÷Òý»o¹ØÁªË÷Òý£(C)¼ÓÈe*½À¨ºÅÖС£ÀýÈ磺

$fruit[0] = ¡®banana';

$fruit[1] = ¡®apple';

$favorites['animal'] = ¡®tiger';

$favorites['sports'] = ¡®basketball';

Èç¹uÓû§ÔÚÏoÊý×e¸³ÖµÊ±²»Ö¸Ã÷Êý×eϱe£¬PHP½«×Ô¶¯°Ñ¸Ã¶ÔÏo¼ÓÈeµ½Êý×eÄ(C)β¡£ÀýÈç¶ÔÓÚÉÏÊo$fruitÊý×e¿ÉÒÔÓÃÒÔÏÂ*½Ê½¸³Öµ¶ø±£³Ö½a¹u²»±a£¬

$fruit[] = ¡®banana';

$fruit[] = ¡®apple';

ͬÑu£¬ÔÚPHPÖУ¬Óû§»¹¿ÉÒÔ¸u¾ÝÐeÒª½¨Á¢¶aάÊý×e¡£ÀýÈ磺

$people[¡®David'][¡®shirt'] = ¡®blue';

$people[¡®David'][¡®car'] = ¡®red';

$people[¡®Adam'][¡®shirt'] = ¡®white';

$people[¡®Adam'][¡®car'] = ¡®silver';

ÔÚPHPÖУ¬Óû§»¹¿ÉÒÔʹÓÃarray()º¯Êý¿iËÙ½¨Á¢Êý×e¡£ÀýÈ磺

$fruit = array(¡®banana',¡®apple');

$favorites = array(¡®animal' = > ¡®tiger', ¡®sports' = > ¡®basketball');

»oÕßʹÓÃarray()º¯Êý´´½¨¶aάÊý×e£º

$people = array (¡®David' = > array(¡®shirt' = > ¡®blue','car' = > ¡®red'),

¡®Adam' = > array(¡®shirt' = > ¡®white',¡®car' = > ¡®silver'));

´ËÍa£¬PHP»¹Ìa¹(C)ÁËÄÚÖú¯Êýcount()ÓÃÓÚ¼ÆËaÊý×eÖеÄÔªËØÊýÁ¿¡£ÀýÈ磺

$fruit = array(¡®banana', ¡®apple');

print count($fruit);

ÏÔʾ½a¹uΪ2¡£

D. ½a¹¹¿ØÖÆ

ÔÚPHPÖУ¬Óû§¿ÉÒÔʹÓá°for¡±»o¡°while¡±µÈµÄÑ­»*½a¹¹Ói¾a¡£ÀýÈ磺

for ($i = 4; $i < 8; $i++) {

print ¡°I have eaten $i apples today.\n¡±£» }

»o

$i = 4; while ($i < 8) {

print ¡°I have eaten $i apples today.\n¡±;

$i++;

}

*µ»Ø½a¹uΪ£º

I have eaten 4 apples today.

I have eaten 5 apples today.

I have eaten 6 apples today.

I have eaten 7 apples today.

´ËÍa£¬Óû§»¹¿ÉÒÔʹÓá°if¡±ºÍ¡°elseif¡±µÈµÄÑ¡ÔñÐÔ½a¹¹Ói¾a¡£ÀýÈ磺

if ($user_count > 200) {

print ¡°The site is busy right now!¡±;}

elseif ($user_count > 100) {

print ¡°The site is active right now!¡±;

else {

print ¡°The site is idle - only $user_count user logged on.¡±;

}

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例