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

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä17½g) ªí³æÄæ¦ì¸ê®Æ¨Ï¥Î ¤W½g

[±Ð¾Ç] (PHP+IIS+MsSQL±Ð¾Ç²Ä17½g) ªí³æÄæ¦ì¸ê®Æ¨Ï¥Î ¤W½g

ªí³æÄæ¦ì¸ê®Æªº¨Ï¥Î
¦b¤W¤@½g±Ð¾Ç¤¤¡A§Ú­Ì¶È´Nªí³æªº¸ê®Æ¶Ç»¼¤è¦¡¥[¥H»¡©ú¡A½d¨Ò¤¤ªºªí³æ¤¸¥ó¡u³æ¦æ¤å¦r¿é¤J¤¸¥ó¡]Text¡^¡v»P¡u¦h¦æ¤å¦r¿é¤J¤¸¥ó¡]Textarea¡^¡v¨Ã¨S¦³¥[¥H»¡©ú¡A¨Æ¹ê¤W¡Aªí³æªº¤¸¥ó¬Û·íªº¦h¡A¦Óªí³æ»Pªí³æ¤¸¥ó¦b§Ú­ÌPHP¤¤§Q¥Î¨ìªº¾÷·|«D±`ªº¦h¡A©Ò¥H¦³¥²­n¤UÂI¥\¤Ò¹ïªí³æ¤¸¥ó¦h¼ô±x¤@ÂI¡A¦b»¡©ú³o¨Ç¤¸¥óªº¦P®É¡Aµ§ªÌ±N·|´N³o¨Ç¤¸¥óÄæ¦ì¬ÛÃöªºPHP¨ç¼Æ»Pª«¥ó¤èªk¥[¥H¤¶²Ð¡C


³æ¦æ¤å¦r¿é¤J¤¸¥ó¡]Text¡^
³æ¦æ¤å¦r¿é¤J¤¸¥ó¬Oªí³æ¤¤ªº°ò¦¤¸¥ó¡A¥X²{¾÷²v¦Ê¤À¤§¤E¤Q¥H¤W¡A¨Ò¦p©m¦W¡B¦í§}¡B¹q¸Ü..µ¥µ¥¸ê®Æªº¿é¤J³£·|¥Î¨ì¥¦¡G
  1. Äæ¦ì»¡©ú¤å¦r¡G<Input Type=¡¨Text¡¨ Name=¡¨ÃѧO¦W¡¨>
½Æ»s¥N½X
¨Ò¦p¡G
  1. ¦a§}¡G<Input Type=¡¨Text¡¨ Name=¡¨Address¡¨>
½Æ»s¥N½X
­Y±z­n­­¨î¥i¿é¤Jªº¦r¼Æ¥i¥[¤W¡uMaxlength¡vÄÝ©Ê¡A­Y¸ê®Æ¬O­n¼g¤J¸ê®Æ®w¡A³o­Ó¦r¼Æ­­¨î¬O¦³¥²­n­­©wªº¡AÁקK¨Ï¥ÎªÌ¬G·N¿é¤J¤j¶qªº¤å¦r¡A³y¦¨¸ê®Æ®wÄæ¦ìªø«×¤£¨¬¡A¨Ò¦p­­¨î³Ì¤j¿é¤J¦r¼Æ¬°50­Ó¦r¡G
  1. ¦a§}¡G<Input Type=¡¨Text¡¨ Name=¡¨Address¡¨ Maxlength=¡¨50¡¨>
½Æ»s¥N½X
¥t¥~¡A¡uSize¡vÄÝ©Ê¥i³]©w³æ¦æ¤å¦r¿é¤J¤¸¥óªºÅã¥Ü¼e«×¡F¡uValue¡vÄÝ©Ê¥i³]©w¥X²{¦b³æ¦æ¤å¦r¿é¤J¤¸¥ó¤¤ªº¹w³]­È¡A¨Ò¦p¡G
  1. ¦a§}¡G<Input Type=¡¨Text¡¨ Name=¡¨Address¡¨ Value=¡§½Ð¿é¤J¤áÄy¦a§}¡¨>
½Æ»s¥N½X
¦bPHP¤¤¦³¨Ç¨ç¼Æ¬O»P¤å¦r¿é¤Jªº¸ê®Æ³B²z¦³±K¤ÁªºÃö«Y¡A¨Ò¦p¨Ï¥ÎªÌ¬G·N¥[¤JHTML¼ÐÅÒ¡A³y¦¨¸ê®Æ¦bÅã¥Ü®É¥X²{¤£¥¿±`±Æ¦C¡A³y¦¨­¶­±±Æª©®æ¦¡¶Ã±¼¡A¦¹ºØª¬ªp³Ì±`¥X²{ªº´N¬O¦b¡u¯d¨¥ª©¡v©Î¡u°Q½×°Ï¡v¡A¦¹®É´N¥i¨Ï¥Î¡uhtmlspecialchars()¡v¨ç¼Æ¨Ó³B²z¡G
htmlspecialchars ()¨ç¼Æ®æ¦¡
  1. string htmlspecialchars ( string string [, int quote_style [, string charset]])
½Æ»s¥N½X
  1. <html><head>
  2. <title>³æ¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <form action="text_ans.php" method="Post">
  5. ¦a§}:
  6. <input type="Text" name="Address">
  7. <input type="Submit">
  8. </form>
  9. </body></html>
½Æ»s¥N½X
  1. <html><head>
  2. <title>³æ¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <?
  5. $myaddress=$_REQUEST["Address"];
  6. ?>
  7. Ãö³¬HTML¼ÐÅҨϥÎ:<?=htmlspecialchars($myaddress)?>
  8. <P>
  9. ¶}©ñHTML¼ÐÅҨϥÎ:<?=$myaddress?>
  10. </body></html>
½Æ»s¥N½X
§Q¥Î¡uhtmlspecialchars¡v¤èªk¥i±NÄæ¦ì¤ºªº¸ê®Æ¥[¥H½s½X¡Aµ²ªG´N¦¨¬°¡u&lt;B&gt;¥x¥_¿¤&lt;/B&gt;¡v¡AÂsÄý¾¹¹J¨ì³oºØ¯S®í¦r¤¸´N·|¥[¥H¸Ñ½X¦¨¤å¦rÅã¥Ü¥X¨Ó¡A¦Ó¤£·|±N¨ä·í¦¨HTML¼ÐÅÒ¨Ó¸ÑŪ¡C


­Y­n­pºâ¨Ï¥ÎªÌ©Ò¿é¤Jªº¸ê®Æªø«×¡]¦r¤¸¼Æ¡^¡A¥i¨Ï¥Î¡ustrlen¨ç¼Æ¡A¦pªG¬OªÅ¦r¦ê«hªø«×¬°0¡A¯S§O­nª`·N¡GªÅ¥Õ¦r¤¸¤]¦û¥Î¤@­Ó¦r¤¸ªø«×¡C
¬°¤F½T«O¸ê®Æªº¿é¤J¥¿½T©Ê¡AÁקKªÅ¥Õ¦r¤¸ªº»~¿é¤J»P­pºâ¸ê®Æªø«×ªº¥¿½T©Ê¡A§Ú­Ì¥i¥H§Q¥Î¡utrim()¡v¨ç¼Æ²¾°£¸ê®Æ¦r¦ê¥ª¥k¨âÃ䪺ªÅ¥Õ¦r¤¸¡A¦ý¬O§¨Âø©ó¦r¤¸»P¦r¤¸¶¡ªºªÅ¥Õ¦r¤¸¨Ã¤£·|³Q®ø°£¡C
  1. <form action="text_ans_2.php" method="Post">
  2. ¦a§}:
  3. <input type="Text" name="Address">
  4. <input type="Submit">
  5. </form>
½Æ»s¥N½X
¨Ò¦p¡G¬G·N©ó¸ê®Æ«e¤è¥[¤J¤T­ÓªÅ¥Õ¦r¤¸¡A¸ê®Æ¤¤¶¡»P«á¤è¦U¥[¤J¤@­ÓªÅ¥Õ¦r¤¸¡G
  1. <html><head>
  2. <title>³æ¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <?
  5. $myaddress=$_REQUEST["Address"];
  6. ?>
  7. ­ì©l¸ê®Æ:<?=$myaddress?><Br>
  8. ªø«×:<?=strlen($myaddress)?><Br>
  9. <P>
  10. ¥h¨âÃäªÅ¥Õ¸ê®Æ:<?=trim($myaddress)?><Br>
  11. ªø«×:<?=strlen(trim($myaddress))?><Br>
  12. <P>
  13. </body></html>
½Æ»s¥N½X
¦b¤U¹Ï¤¤¡A§Q¥Î¡utrim()¡vµ¥¨ç¼Æ²¾°£¸ê®Æ¦r¦ê¥ª¥k¨âÃ䪺ªÅ¥Õ¦r¤¸¡A¦A§Q¥Î¡ustrlen()¡v¨ç¼Æ­pºâ¸ê®Æªø«×¡A±z¥i¥Hµo²{§¨Âø©ó¦r¤¸»P¦r¤¸¶¡ªºªÅ¥Õ¦r¤¸¨Ã¤£·|³Q®ø°£¡A¦Ó¥B¤@­ÓªÅ¥Õ¦r¤¸´N¦û¥Î¤@­ÓªÅ¶¡ªø«×¡Aª`·N¡G¤@­Ó¤¤¤å¦rºâ¨â­Ó¦r¤¸ªø«×¡C




±K½XÄæ¦ì¤¸¥ó¡]Password¡^
±K½XÄæ¦ì¤¸¥ó¡]Password¡^¥~Æ[¤W»P³æ¦æ¤å¦r¿é¤J¤¸¥ó¤@¼Ò¤@¼Ë¡A¦ý¦b±K½XÄæ¦ì¤¸¥ó¤¤¿é¤Jªº¸ê®Æ·|¥H¡u*¡v¬P¸¹Åã¥Ü¡G
  1. Äæ¦ì»¡©ú¤å¦r¡G<Input Type=¡¨Password¡¨ Name=¡¨ÃѧO¦W¡¨>
½Æ»s¥N½X
¨Ò¦p¡G
  1. ±K½X¡G<Input Type=¡¨Password¡¨ Name=¡¨paswd¡¨>
½Æ»s¥N½X
¥t¥~¡A±K½XÄæ¦ì¤¸¥ó»P³æ¦æ¤å¦r¿é¤J¤¸¥ó¤@¼Ë¡A³z¹L¡uSize¡vÄÝ©Ê¥i³]©wÅã¥Üªº¼e«×¡F¡uValue¡vÄÝ©Ê¥i³]©w¥X²{¦b¤¸¥ó¤¤ªº¹w³]­È¡A¤£¹L¡AÀ³¸Ó¨S¦³¤H·|¬°±K½XÄæ¦ì¤¸¥ó«Ø¥ß¹w³]­È§a¡I


      ´£¥Ü¡I¡I
±K½XÄæ¦ì¤¸¥ó¦b¸ê®Æ¿é¤J®É·|¥H¬P¸¹¨ú¥N©Ò¿é¤Jªº¤å¦r¡A¦ý¦b¦øªAºÝŪ¨úªº¸ê®Æ¨ÌµM¬O¨Ï¥ÎªÌ©Ò¿é¤Jªº­ì©l¸ê®Æ¡A¦P¼Ë¦a¡A­Yªí³æ¨Ï¥Î¡uGet¡vªº¤è¦¡¶Ç»¼ªí³æ¸ê®Æ¡A¨Ï¥ÎªÌ©Ò¿é¤Jªº­ì©l¸ê®Æ¤]·|ªþ¦bºô§}«á¤è¦ÓÅã¥Ü¦bÂsÄý¾¹ªººô§}¦C¤¤¡A©Ò¥H¡A·íªí³æ¤¤§t¦³±K½XÄæ¦ì¤¸¥ó®É¡Aªí³æ¸ê®Æªº¶Ç»¼¤è¦¡À³±Ä¥Î¡uPost¡v¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

¦h¦æ¤å¦r¿é¤J¤¸¥ó¡]Textarea¡^
¦pªG¿é¤Jªº¸ê®Æ¶q¤£¦h¡A¨º»ò³æ¦æ¤å¦r¿é¤J¤¸¥ó¬O³Ì¾A¦Xªº¤¸¥ó¡A¦ý¬O¡A¦b»Ý­n¤j¶q¿é¤J¸ê®Æªº³õ¦X´NÀ³¸Ó¨Ï¥Î¦h¦æ¤å¦r¿é¤J¤¸¥ó¡]Textarea¡^¤ñ¸û¾A¦X¡G
  1. <textarea name=¡¨ÃѧO¦W¡¨ cols=¡¨Äæ¼Æ¡¨ rows=¡¨¦C¼Æ¡¨></textarea>
½Æ»s¥N½X
¦h¦æ¤å¦r¿é¤J¤¸¥ó§Q¥Î¡ucols¡vÄݩʨӳ]©wÅã¥Üªº¼e«×¡]¦r¼Æ¡^¡A¦]¬°¥¦¥i¥H¿é¤J¦h¦æ¤å¦r¡A©Ò¥H¤S¦³¡urows¡vÄݩʨӳ]©wÅã¥Üªº°ª«×¡]¦æ¼Æ¡^¡A¦]¬°¦h¦æ¤å¦r¿é¤J¤¸¥ó¥i¿é¤Jªº¸ê®Æ¶q¤ñ¸û¤j¡A·íªí³æ¤¤§t¦³¦h¦æ¤å¦r¿é¤J¤¸¥ó®É¡Aªí³æ¸ê®Æªº¶Ç»¼¤è¦¡À³±Ä¥Î¡uPost¡v¡A¥HÁקK¶Ç°eªº¸ê®Æ³QºIÂ_¡C


¬°ÁקK¿é¤Jªº¸ê®Æ¤¤§t¦³HTML¼ÐÅÒ¦Ó³y¦¨§xÂZ¡A¦h¦æ¤å¦r¿é¤J¤¸¥ó¤]¦h·|°t¦X¡uhtmlspecialchars()¡v¨ç¼Æ¨Ó³B²z¡C
  1. <html><head>
  2. <title>¦h¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <form action="textarea_ans.php" method="Post">
  5. ½Ð¿é¤J¯d¨¥:<Br>
  6. <Textarea name="content" cols="35" rows="5">
  7. </Textarea><Br>
  8. <input type="Submit">
  9. </form>
  10. </body></html>
½Æ»s¥N½X
¥t¥~¡A·í§Ú­Ì±N¿é¤J©ó¦h¦æ¤å¦r¿é¤J¤¸¥óªº¸ê®ÆÅã¥Ü¥X¨Ó®É¡A·|¦³¤@­ÓÂ_¦æªº°ÝÃD¡A¿é¤J¸ê®Æ®É¡A¦b¦h¦æ¤å¦r¿é¤J¤¸¥ó¤¤«ö¤U¡uEnter¡v·|¦³´«¦æªº®ÄªG¡AÁöµM¦bªí­±¤W¬Ý¤£¨ì¥ô¦óªº´«¦æ¦r¤¸¡A¦ý¹ê»Ú¤W«o¯u¹ê¦s¦bµÛ¤@­Ó´«¦æ¦r¤¸¡A³o­Ó´«¦æ¦r¤¸¦b§Ú­Ì¿é¥X¨ìÂsÄý¾¹®É¨Ã¤£·|¦³´«¦æªº®ÄªG¡A¦]¦¹¡A¿é¥X®ÉÀ³¥ý¨Ï¥Î¡unl2br()¡v¨ç¼Æ±N³o­Ó´«¦æ¦r¤¸´À´«¦¨¡u<Br>¡vªºHTML¼ÐÅҲŸ¹¡C
nl2br ()¨ç¼Æ®æ¦¡
  1. string nl2br ( string string)
½Æ»s¥N½X
  1. <html><head>
  2. <title>¦h¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <?
  5. $mycontent=$_REQUEST["content"];
  6. ?>
  7. ­ì©l¸ê®Æ(¥¼¸m´«):<Br>
  8. <?=$mycontent?>
  9. <P>
  10. ­ì©l¸ê®Æ(¤w¸m´«):<Br>
  11. <?=nl2br($mycontent)?>
  12. </body></html>
½Æ»s¥N½X



¦³®É­Ô¡A§Ú­Ìªº¿é¤Jª©­±»P¸ê®Æ¿é¤Jª©­±ªº°t¸m¤£¦P¡A¦pªG¨Ì­ì©l¸ê®Æ®æ¦¡¨Ó¿é¥X¡A¥i¯à³y¦¨§Ú­Ìºô­¶±Æª©ªº°ÝÃD¡A¦]¦¹¡A¥ç¥i¥H¨Ï¥Î¡uwordwrap()¡v¨ç¼Æ¨Ó«ü©w¨C¤@¦æ¸ê®Æªº¿é¥Xªø«×¡G
wordwrap()¨ç¼Æ®æ¦¡
  1. string wordwrap ( string str [, int width [, string break [, boolean cut]]])
½Æ»s¥N½X

¤å¦r§é¦æ¡C
  1. <html><head>
  2. <title>¦h¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <?
  5. $mycontent=$_REQUEST["content"];
  6. ?>
  7. ­ì©l¸ê®Æ(¥¼´«¦æ):<Br>
  8. <?=$mycontent?>
  9. <P>
  10. ­ì©l¸ê®Æ(¤w´«¦æ):<Br>
  11. <?
  12. $newword=wordwrap($mycontent,40,"<br>",1);
  13. echo "$newword";
  14. ?>
  15. </body></html>
½Æ»s¥N½X
§Ú­Ì±`¦b¯d¨¥ªO©Î°Q½×°Ï¤¤¨£¨ì¦³¨Çºô¤Í«Ü³ßÅw½|ż¸Ü¡A­n¸Ñ¨M¥X²{¤£¶®¦r¥yªº¿ìªk¡A´N¬O±Nż¸Ü¹LÂo±¼¡A§â¥¦´«¦¨¤å¦r©Î°®¯Ü®ø°£¥¦¡A­Y­n¸m´«±¼¦r¦ê¤¤ªº¬Y¨Ç¦r¥y¥i¨Ï¥Î¡ustr_replace()¡v¨ç¼Æ¡G
str_replace()¨ç¼Æ®æ¦¡
  1. mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count])
½Æ»s¥N½X
¨Ò¦p¡G
  1. <?
  2. $testword="§A¯u¬O­ÓÃa³J";
  3. $newword=str_replace("Ãa³J","bad man",$testword);
  4. echo $newword; //¿é¥X'§A¯u¬O­Óbad man'
  5. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

³æ¿ï«ö¶s¡]Radio¡^
³æ¿ï«ö¶s¡]Radio¡^¾A¥Î©ó¦h³Æ¿ï®×µª®×¥B³æ¤@µª®×¿ï¨úªº³õ¦X¡A¦p¦P³æ¿ïªº¿ï¾ÜÃD¡A¨Ò¦p¦å«¬¡B©Ê§O¡Kµ¥¡G
  1. <input type=¡¨Radio¡¨ name=¡¨ÃѧO¦W¡¨ value=¡¨¸ê®Æ­È¡¨>
½Æ»s¥N½X
¥Ñ©ó¨Ï¥ÎªÌ¥u»ÝÂI¿ïµª®×¡A¤£»Ý­n¶ñ¼g¸ê®Æ¡A©Ò¥H§Ú­Ì¥²¶·¬°¨C¤@­Ó³æ¿ï«ö¶s«Ø¥ß¤£¦Pªº¸ê®Æ­È¡A³Ì­«­nªº¬O¡G¬°¤FÅý¦h­Ó³æ¿ï«ö¶s¦¨¬°³æ¿ïªº¸s²Õ¡A¬G¦P¸s²Õ¤ºªº³æ¿ï«ö¶s¨ä¡uname¡vÄÝ©Ê­È¥²¶·¬°¬Û¦Pªº¡uÃѧO¦W¡v¡C
  1. <html><head>
  2. <title>³æ¿ï«ö¶s¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <form action="radio_ans.php" method="Post">
  5. ½Ð¿ï¾Ü¦å«¬:<Br>
  6. <Input type="Radio" name="blood" value="A" Checked>A
  7. <Input type="Radio" name="blood" value="B">B
  8. <Input type="Radio" name="blood" value="O">O
  9. <Input type="Radio" name="blood" value="AB">AB
  10. <Br>
  11. <input type="Submit">
  12. </form>
  13. </body></html>
½Æ»s¥N½X
­Y§Ú­Ì­n±N¬Y­Ó³æ¿ï«ö¶s¹w³]¬°¤w¿ï¨ú¡A«h¥i¥[¤J¡uChecked¡vÄݩʳ]©w¡A¨Ò¦p±N¦å«¬Aªº¶µ¥Ø³]¬°¹w¥ý¿ï¨ú¡u<Input type="Radio" name="blood" value="A" Checked>¡v¡A·íºô­¶¤@¶}±Ò«á¡A¡uA¡v³o­Ó³æ¿ï«ö¶s§Y¬°¿ï¨úª¬ºA¡C

·í¨Ï¥ÎªÌ¿ï¨ú¤F¬Y­Ó³æ¿ï«ö¶s«á¡A¨º»ò¿ï¨ú¶µ¥Øªº¤Á´«¶È­­©ó¦P¥þ¤¤ªº¨ä¥L³æ¿ï«ö¶s¡A¨S¦³¿ìªk¨ú®ø¦Ó¤£¿ï¨ú¸s²Õ¤¤ªº¥ô¦ó³æ¿ï«ö¶s¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ·R¤£¬O­n¨D¹ï¤è¡A¦Ó¬O­n¥Ñ¦Û¨­ªº¥I¥X¡C
ªð¦^¦Cªí ¤W¤@¥DÃD