ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä15½g) ¸ê®ÆªºÅª¨ú»P¿é¥X ¤¤½g

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä15½g) ¸ê®ÆªºÅª¨ú»P¿é¥X ¤¤½g

¸ê®Æ¿é¥X
¦b«e­±³¹¸`¤¤¡A­n¿é¥X¸ê®Æ¨ìºô­¶µe­±¤¤¡Aµ§ªÌ¨Ï¥Î¤Fecho()¨ç¼Æ¡A¥i¬Oµ§ªÌ¤S¨Ï¥Î¤F«Ü¦h¤£¦Pªº®æ¦¡¡A±z¥i¯à§Ë±o¤@¹ÎÃú¤ô¡A©Ò¥H¥»³¹¸`±N»¡©ú¤@¤U¡A¤S¡A°£¤Fecho()¨ç¼Æ¥i¿é¥X¸ê®Æ¨ìºô­¶µe­±¤¤¥~¡AÁÙ¦³´X­Ó¨ç¼Æ¤]¦³¸ê®Æ¿é¥Xªº¥\¯à¡A³o¨Ç¨ç¼Æ§Ú­Ì¤]­n»{ÃѤ@¤U¡C


echo()¨ç¼Æ
echo()¨ç¼Æ­t³d±N¦r¦ê¸ê°T¿é¥X¦Ü¨Ï¥ÎªÌºÝ¡A¤]¥i»PHTML¼Ð¥Ü²V¦X¨Ï¥Î¡A¼Ð·Ç®æ¦¡¦p¤U¡G
¼Ð·Çecho()¨ç¼Æ®æ¦¡
  1. echo ( string arg1 [, string argn...]);
½Æ»s¥N½X
¨Ò¦p¡G
  1. <?
  2. echo (¡§³o¬O¥ÑPHP¿é¥Xªº¤å¦r¡¨);
  3. ?>
½Æ»s¥N½X
¬Ý¨ì¤F§a¡I¼Ð·Çªºecho()¨ç¼Æ¥Îªk¬O±N¦r¦ê¤º®e¥Î¤@²Õ¬A¸¹¥]°_¨Ó¡A¦Ó­n¿é¥Xªº¦r¦ê¦A¥Î¤@¹ïÂù¤Þ¸¹¬A°_¨Ó¡A¦]¬°echo()¨ç¼Æ¬O¥Î¨Ó¿é¥X¦r¦ê¸ê®Æªº¡C

¦n²Ö³á¡I¤S¬O¬A¸¹¤S¬OÂù¤Þ¸¹ªº¡A¶û³Â·Ð£«¡A¨º¦n¡A§Ú­Ì§â³Ì¥~­±ªº¬A¸¹®³±¼¡A³o¼Ë¤]¦æ¡G
  1. <?
  2. echo ¡§³o¬O¥ÑPHP¿é¥Xªº¤å¦r¡¨;
  3. ?>
½Æ»s¥N½X
¥i¬O¡A§Ú¦³¯S©wªºÅܼƭȭn¸ò¦r¦ê¤@°_¿é¥X­C¡I¨SÃö«Y¡I§Ú­Ì¥Î¡u.¡v¤p¶ÂÂI§â¥¦³s°_¨Ó¡A¡u.¡v¤p¶ÂÂI«e«á­n¥[ªÅ®æ¡]space¡^³á¡I±z¤£¥Î¾á¤ß³o­ÓªÅ®æ¡Aecho()¨ç¼Æ¦b¿é¥X¸ê®Æ®É·|©¿²¤±¼³o¨ÇªÅ®æ¡G
  1. <?
  2. $x="PHP";
  3. echo "³o¬O¥Ñ" . $x . "¿é¥Xªº¤å¦r";
  4. ?>
½Æ»s¥N½X
±z¤S¶û³Â·Ð¤F³á¡I¨SÃö«Y¡I§â¡u.¡v¤p¶ÂÂI®³±¼§a¡I±NÅܼƸò¦r¦ê¥þ³¡©ñ¦bÂù¤Þ¸¹¤¤´N¦n¡G
  1. <?
  2. $x="PHP";
  3. echo "³o¬O¥Ñ$x ¿é¥Xªº¤å¦r";
  4. ?>
½Æ»s¥N½X
¦b¤W¨Ò¤¤¡AÅܼƪº$¦r¤¸«e¥i¥H¤£¥[ªÅ®æ¡A¦ý¬OÅܼƦWºÙ«á­n¥[­ÓªÅ®æ¡A¤£µMPHP·|§â¡u$x¿é¥Xªº¤å¦r¡v·í¦¨¬O¤@­ÓÅܼơA¦Ó³y¦¨µ{¦¡¿ù»~¡A¤£¹L¡A³o­ÓªÅ®æecho()¨ç¼Æ¦b¿é¥X¸ê®Æ®É¤£·|©¿²¤±¼¡A·|©Þ¥¦·í¦¨¬O¦r¦êªº¤º®e¡C

¨º§Ú­n¦P®É¦L¥XÅܼƦWºÙ¸òÅܼƭȮɸӦp¦ó°µ¡H­n¦L¥XÅܼƦWºÙ«h¥²¶·©óÅܼƪº¡u$¡v¤§«e¥[¤W¤Ï±×½u¡u\¡v¡A­ì¦]¦b©ó¡u$¡v¬°¤@­Ó²æ¶h¦r¤¸¡A¥Î¨ÓÃѧOÅܼơG
  1. <?
  2. $x="PHP";
  3. echo " $x ";   //¦L¥XÅܼƭȡ¨PHP¡¨
  4. echo " \$x ";  //¦L¥XÅܼƦWºÙ¡¨$x¡¨
  5. ?>
½Æ»s¥N½X
­Y­n±NHTML¼ÐÅÒ¥[¤Jecho()¨ç¼Æªº¿é¥X¸ê®Æ®É¡A¦]¬°HTML¼ÐÅÒªºÄݩʳ]©w­È¦h·|¥HÂù¤Þ¸¹¬A°_¨Ó¡A¦Ó³o­ÓÂù¤Þ¸¹¤S¬OPHPªº²æ¶h¦r¤¸¤§¤@¡A©Ò¥H¡A¤d¸U§O§Ñ¤F¦b¡u¡¨¡v¤§«e¥[¤W¤Ï±×½u¡u\¡v¡G
  1. <html>
  2. <head>
  3. <title>ex05_07</title>
  4. </head>
  5. <body>
  6. ¤j®a¨Ó¾ÇPHP
  7. <hr>
  8. ¤µ¤Ñ¬O:
  9. <?echo "<font color=\"#FF0000\">" . date("Y¦~m¤ëj¤é");?>
  10. </body>
  11. </html>
½Æ»s¥N½X
¤W¨Ò°õ¦æµ²ªG¦p¤U¹Ï©Ò¥Ü¡A§Ú­Ì¥i¥H«Ü²M·¡ªº¬Ý¨ìPHPºô­¶°õ¦æ«áªºµe­±¡A§Ú­Ì§Q¥Î¡yecho()¡z¤èªk¿é¥X¤F¤@­Ó¤é´Á¸ê®Æ¡A¦Ó³o­Ó³o­Ó¤é´Á¦r¦ê§Ú­ÌÁÙ¥[¤W¤FHTML¼ÐÅÒ¡u<font color="#FF0000">¡v¨Ó³]©w¥¦ªº¤å¦rÃC¦â¡A°ÝÃD¬O¼ÐÅÒ¤º¨Ï¥Î¤FÂù¤Þ¸¹¡A¦b¡u¡¨¡v¤§«e¥[¤W¦A¥[¤W¤Ï±×½u¡u\¡v¡C
CH5_15.png

¦pªG§Ú³ßÅw±N¤£·|Åܰʪººô­¶¸ê®Æ¤]§Q¥Îecho()¨ç¼Æ¨Ó½s¼g¡A¥i¤£¥i¥H©O¡H·íµM¤]¥i¥H¡I¦ý¬O¡A³o¼Ë´NÅܦ¨½s¼g¤@¤ä§¹¾ãªºPHPµ{¦¡¤F¡A©Ò¥H¥þ³¡ªº±Ô­z³£¥²¶·©ñ¦b ¡y<? ¡z»P¡y?>¡z¤§¤¤¡A¦P®É¡A©Ò¦³ªºHTML¼ÐÅÒ³£¥²¶·¼g¦bÂù¤Þ¸¹ ¡y " ¡z¤§¤¤:
  1. <?
  2. echo "<html>";
  3. echo "<head>";
  4. echo "<title>ex05_08</title>";
  5. echo "</head>";
  6. echo "<body>";
  7. echo "¤j®a¨Ó¾ÇPHP";
  8. echo "<hr>";
  9. echo "¤µ¤Ñ¬O:";
  10. echo "<font color=\"#FF0000\">" . date("Y¦~m¤ëj¤é");
  11. echo "</body>";
  12. echo "</html>";
  13. ?>
½Æ»s¥N½X
¤W¨â­Ó½d¨Òªº¼gªk¡A¨äµ²ªG¬O¬Û¦Pªº¡Aµ§ªÌ­Ó¤H¤ñ¸û³ßÅw²Ä¤@ºØHTML¼ÐÅÒ¸ê®Æ²V¦X¼gªº¤è¦¡¡A¦Ü¤Ö¤£¥Î¥´¨º»ò¦h¦r¡A¤£¹L¡A¦³«e½ú«ü¥X¡AHTML¼ÐÅÒ¸ê®Æ²V¦X¼gªº¤è¦¡¦b°õ¦æ®Ä²v¤W¸û®t¡A¦]¬°¨t²Î·|¦bHTML¸ÑªR»PPHP Engine«ùÄò¤Á´«¡A¦p¦ó¦b¶}µo®É¶¡»P¨t²Î°õ¦æ®Ä²v¶¡¨ú±Ë´N¬Ý±zÅo¡I



²¤Æecho()¨ç¼Æ±Ô­z
¦b«e­±´X­Ó³¹¸`¡Aµ§ªÌ³£¨S¦³¨Ï¥Î²¤Æªº¿é¥X±Ô­z¡A¥¦ªº¥ÎªkÃþ¦üASPªº¡u<%=XXX%>¡v±Ô­z¼gªk¡A¨Ò¦p¡G
  1. <?echo date("Y¦~m¤ëj¤é");?>
  2. <?=date("Y¦~m¤ëj¤é")?>
½Æ»s¥N½X
¤W¨Òªº¨â¦æµ{¦¡±Ô­z°õ¦æµ²ªG³£¬O¤@¼Ë¦a¡A«áªÌ¦ü¥G¤ñ¸û²©ú¹ï§a¡I¦ý¬O¡A²¤Æªº¡u<?=XXX?>¡v ±Ô­z¥u¯à¦b³æ¦æ±Ô­z¯à¥Î³á¡I¦b±Ô­z°Ï¶ô¤¤¬O¤£¯à¥Îªº¡A¨Ò¦p¤U¨Ò¡G
  1. <?
  2. echo "¤j®a¨Ó¾ÇPHP";
  3. echo "<hr>";
  4. ="¤µ¤Ñ¬O:"
  5. echo "<font color=\"#FF0000\">" . date("Y¦~m¤ëj¤é");
  6. ?>
½Æ»s¥N½X
¦pªG±N¡u="¤µ¤Ñ¬O:"¡v³o¦æ±Ô­z¿W¥ß¥Î¤@²Õ¡u<? ?>¡v¬A°_¨Ó´N¥i¥H¤F¡G
  1. <?
  2. echo "¤j®a¨Ó¾ÇPHP";
  3. echo "<hr>";
  4. ?>
  5. <?="¤µ¤Ñ¬O:"?>
  6. <?
  7. echo "<font color=\"#FF0000\">" . date("Y¦~m¤ëj¤é");
  8. ?>
½Æ»s¥N½X
«¢¡I³o¼Ë¦n¹³¦³ÂIµe³D²K¨¬¡Iµ§ªÌ«Øij¡G¦bµ{¦¡°Ï¶ô¤¤§@¿é¥X´N¨Ï¥Î§¹¾ãªºecho()¨ç¼Æ±Ô­z¡A­Y¬O¦b»PHTML¼ÐÅÒ¸ê®Æ²V¦Xªº³õ¦X¤~¨Ï¥Î¡u<?=XXX?>¡vªº±Ô­z¼gªk¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

print() ¨ç¼Æ
print()¡G¤]¬O¥Î¨Ó¿é¥X¸ê®Æªº¡A¥Îªk¤]¦p¦Pecho()¤@¯ë¡G
  1. <?
  2. print "¤j®a¨Ó¾ÇPHP";
  3. print "<hr>";
  4. ?>
  5. <?="¤µ¤Ñ¬O:"?>
  6. <?
  7. print "<font color=\"#FF0000\">" . date("Y¦~m¤ëj¤é");
  8. ?>
½Æ»s¥N½X
print()ÁöµM¥i¥H±N¸ê®Æ¿é¥X¨ìºô­¶µe­±¤¤¡A¦ýecho()¥i¥H§Q¥Î¡u¡A¡v³r¸¹¨Ó¦X¨Ö¦C¦L¦h¶µ¸ê®Æ¡Aprint()«o°µ¤£¨ì¡G
  1. <?
  2. $x="§Ú·R";
  3. $y="PHP";
  4. echo $x . $y; //¦L¥X'§Ú·Rphp'
  5. echo $x,"PHP"; //¦L¥X'§Ú·Rphp'
  6. print $x . $y; //¦L¥X'§Ú·Rphp'
  7. print $x,$y;  //¿ù»~,print()¤£»{ÃÑ','³r¸¹
  8. ?>
½Æ»s¥N½X
¥H¤W¨Ò¨Ó¬Ý¡Aprint()¦ü¥G¤£¦pecho()¦³¥Î¡A¨Æ¹ê¤£µM¡Aprint()¦³¥¦¯S§Oªº§@¥Î¡Aecho()¥uºÞ±N¸ê®Æ°µ¿é¥Xªº°Ê§@¡A¸ê®Æ¦³¨S¦³¥¿½Tªº¿é¥X¡Aecho()¨Ã¤£·|§i¶D±z¡A¦Óprint()¦b°µ¸ê®Æ¿é¥Xªº°Ê§@«á¡A·|¦³¦^¶Ç­È¡A³qª¾§Ú­Ì¸ê®Æ¬O§_¤w¥¿½Tªº¿é¥X¡G
  1. <?
  2. $x="§Ú·R";
  3. $y="PHP";
  4. $test=print $x . $y; //¦L¥X'§Ú·Rphp'
  5. print $test; //¸ê®Æ¿é¥X¦¨¥\¦^¶Ç1
  6. ?>
½Æ»s¥N½X
printf()¨ç¼Æ
printf()¨ç¼Æ¥i®Ú¾Ú§Ú­Ìªº®æ¦¡³]©w¨Ó¿é¥X®æ¦¡¤Æªº¦r¦ê¡Aprintf()¨ç¼Æ¸òprint()¨ç¼Æ¤£¦P¡A¸ê®Æ¿é¥X«á¤£·|¦³¦^¶Ç­È¡G
printf()¨ç¼Æ®æ¦¡
  1. void printf ( string format [, mixed args])
½Æ»s¥N½X
¤W¦¡¤¤¡G¡uformat¡v¬°®æ¦¡³]©w¡A¨Ò¦p¡G
  1. <?
  2. $age="20 ·³";
  3. printf("%d" ,"$age"); //¿é¥X20
  4. ?>
½Æ»s¥N½X
¤W¨Ò¤¤¡A§Ú­Ìªº®æ¦¡³]©w¬°¡u%d¡v¤D¬O±N¦r¦ê¡u"20 ·³"¡v®æ¦¡¤Æ¬°¤Q¶i¨î¸ê®Æ¦Ó¿é¥X¡u20¡v¡C
¨Ò¦p¡G¿é¥X¤p¼ÆÂI«á3¦ì¤p¼Æªº¯BÂI«ü¼Æ
  1. <?
  2. $age="20 ·³";
  3. printf("%.3e" ,"$age"); //¿é¥X2.00e+1
  4. ?>
½Æ»s¥N½X
®æ¦¡¤Æªº¦r¦ê¤¤¤]¥i¥H¥]§t§Ú­Ì­nÅã¥Üªº¤å¦r¡A¨Ò¦p¡G
  1. <?
  2. $age="20 ·³";
  3. printf("§Ú%.3e·³" ,"$age"); //§Ú2.00e+1·³  
  4. ?>
½Æ»s¥N½X
¤Uªí¬°®æ¦¡¤Æªº¥i¥Î¸ê®ÆÃþ«¬¡G

Ãþ«¬

»¡©ú

%

®æ¦¡¤Æªº«e¸m²Å¸¹

c

¦r¤¸

s

¦r¦ê

d

¤Q¶i¨î¾ã¼Æ

b

¤G¶i¨î¾ã¼Æ

o

¤K¤G¶i¨î¾ã¼Æ

x

¤p¼gªº¤Q¤»¶i¨î¾ã¼Æ

X

¤j¼gªº¤Q¤»¶i¨î¾ã¼Æ

f

¯BÂI¼Æ

e

«ü¼Æ


printf()¨ç¼Æ¥ç¥i¥Î©ó¸m´«¦P®É®æ¦¡¤Æ¡A¨Ò¦p¡G
  1. <?
  2. $name="©~©ö";
  3. $tall="170";
  4. $me="§Úªº¦W¦r¬O %s ,¨­°ª %X ¤½¤À";
  5. printf($me , $name , $tall);
  6. //¿é¥X:§Úªº¦W¦r¬O ©~©ö,¨­°ª AA ¤½¤À  
  7. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

ÀÉÀY¸ê°T
ÀÉÀY¸ê°T¡Gºô­¶¤å¥ó¤¤³Q<HEAD>¡K</HEAD>¼ÐÅÒ¥]¬A°_¨Óªº¤å¥ó¸ê°T¡A±`¨£ªº¦³¤å¥ó©ïÀY¡]³Q<TITLE>¡K</TITLE>¼ÐÅÒ¥]¬A°_¨Ó¡^¥H¤Î¤å¥óªºÃþ«¬¡B©Ò¨Ï¥Îªº½s½X¦r¶°µ¥¡G
  1. <html>
  2. <head>
  3. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  4. <meta name="ProgId" content="FrontPage.Editor.Document">
  5. <meta http-equiv="Content-Type" content="text/html; charset=big5">
  6. <title>·s¼Wºô­¶1</title>
  7. </head>
  8. <body>
  9. ºô­¶ªºÅã¥Ü¤º®e
  10. </body>
  11. </html>
½Æ»s¥N½X
³o¨ÇÀÉÀY¸ê°T§Ú­Ì³£¥i¥H³z¹LPHPªº¡uheader()¡v¨ç¼Æ¨Ó°µ¿é¥X¡G
header()¨ç¼Æ®æ¦¡
  1. int header ( string string [, bool replace [, int http_response_code]])
½Æ»s¥N½X
¤]´N¬O¡G
  1. header(¡§ºô­¶¸ê°T¦WºÙ: ¸ê°T¤º®e¡¨);
½Æ»s¥N½X
ºô­¶Âà¦V
ºô­¶¸ê°T¡uLocation¡v¥iÂà¦V¨ä¥Lºô­¶©Îºô§}¡A³o­Ó¤èªk¤]´N©Ò¿×ªº¡y¦Û°ÊÃìµ²¡z¡G
  1. header(¡§Locatiom: ±ý«e©¹ªººô§}¡¨);
½Æ»s¥N½X
¨Ò¦p¡G
  1. <?
  2. //¸ü¤Jºô­¶«á¡A¦Û°ÊÂà±µÁåµ²¦Ü»P¥Dºô­¶¦P¤@¥Ø¿ý¤¤ªºmessage.htmºô­¶
  3. header("Location: message.htm");
  4. //¸ü¤J¥Dºô­¶«á¡A¦Û°ÊÂà±µÁåµ²¦Ü¥Dºô­¶¤W¤@¼h¥Ø¿ý¤¤ªºex04_01.aspºô­¶
  5. header("Location: ../ch4/ex04_01.php");
  6. //¸ü¤J¥Dºô­¶«á¡A¦Û°ÊÂà±µÁåµ²¦Ü»P¥t¤@ºô§}¤¤ªººô­¶
  7. header("Location: http://www.twbts.com");
  8. ?>
½Æ»s¥N½X
header()¨ç¼Æ¥u¥i¥Î¦b©|¥¼¦³¥ô¦ó¸ê®Æ¿é¥X¦ÜÂsÄý¾¹¤§«e¤~¥i©I¥s¡C©|¥¼¦³¥ô¦ó¸ê®Æ¿é¥X¦ÜÂsÄý¾¹¤§«e¤~¥i©I¥s¡H³o¬O¤°»ò·N«ä¡H´N¬O¦bµ{¦¡¶}ºÝ²Å¸¹¡y<?¡z¤§«e³£¤£¯à¦³¥ô¦ó¸ê®Æ°Õ¡I¦p¤U¨Ò¡G
  1. <html><body>
  2. <%
  3. Response.Redirect "message.htm"
  4. %>
  5. </body>
  6. </html>
½Æ»s¥N½X
¤W¨Òµ²ªG±N·|Àò±o¤U¹Ïªº¿ù»~°T®§¡G



ºô­¶ªº®É®Ä
ºô­¶¸ê°T¡uExpires¡v¥i¥Î¨Ó³]©wºô­¶ªº¦³®Ä´Á­­¡A·í§Ú­Ìºô­¶·|±`±`§ó·s¡A¾á¤ßÂsÄýªÌ·|Ū¨ìProxy©ÎcacheªºÂºô­¶¸ê®Æ®É¡A§Ú­Ì´N¥i¥H³]©w¡uExpires¡v¡G
  1. <?
  2. header("Expires: " . date("D, d M Y H:i:s") . "GMT");
  3. ?>
  4. <html><body>
  5. Åwªï¥úÁ{!!
  6. </body>
  7. </html>
½Æ»s¥N½X
·í§Ú­ÌÀ˵øÂsÄý¾¹ªº¼È¦s¥Ø¿ý®É¡A±z¥i¥Hµo²{½d¨Òºô­¶¤w³Q³]©w¤F¦³®Ä´Á­­¡G
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¤£©È¨Æ¦h¡A¥u©È¦h¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD