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

5-6 ªí³æÄæ¦ì¸ê®Æªº¨Ï¥Î(5-6-1 ³æ¦æ¤å¦r¿é¤J¤¸¥ó¡]Text¡^)

5-6 ªí³æÄæ¦ì¸ê®Æªº¨Ï¥Î(5-6-1 ³æ¦æ¤å¦r¿é¤J¤¸¥ó¡]Text¡^)

5-6   ªí³æÄæ¦ì¸ê®Æªº¨Ï¥Î
¦b²Ä¤@¸`¤¤¡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



5-6-1   ³æ¦æ¤å¦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
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

¦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
text.php
  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

¹Ï5-19©óÄæ¦ì¤¤¬G·N¿é¤JHTML¼ÐÅÒ¡C

text_ans.php
  1. <html><head>
  2. <title>³æ¦æ¤å¦r¿é¤J¤¸¥ó¨Ï¥Î</title>
  3. </head><body>
  4. <%
  5. myaddress=Request.Form("Address")
  6. %>
  7. Ãö³¬HTML¼ÐÅҨϥÎ:<%= Server.HTMLEncode(myaddress) %>
  8. <P>
  9. ¶}©ñHTML¼ÐÅҨϥÎ:<%=myaddress %>
  10. </body></html>
½Æ»s¥N½X
§Q¥ÎServerª«¥óªº¡uHTMLEncode¡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

¹Ï5-20 ¨Ï¥Î¡uHTMLEncode¡v¤èªk½s½X¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

­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
text_2.php(¸`¿ý)
  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

¹Ï5-22  ¨è·N¿é¤JªÅ¥Õ¦r¤¸¡C
text_ans_2.php
  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

¹Ï5-22  ¥h°£ªÅ¥Õ¦r¤¸»P­pºâ¸ê®Æªø«×¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¤£¦n·N«ä ·Q½Ð°Ý
<%
myaddress=Request.Form("Address")
%>
§Ú¨Ï¥ÎDW Åã¥Ü³o¬q»yªk¿ù»~ ¦ý§Ú¤£ª¾¹D¦p¦ó­×¥¿
ÁٽФj¤j«üÂI
·PÁÂ

TOP

¤£¦n·N«ä ·Q½Ð°Ý

§Ú¨Ï¥ÎDW Åã¥Ü³o¬q»yªk¿ù»~ ¦ý§Ú¤£ª¾¹D¦p¦ó­×¥¿
ÁٽФj¤j«üÂI
·PÁÂ
tokko4286 µoªí©ó 2012-7-15 18:22
  1. <?
  2. $myaddress=$_REQUEST["Address"];
  3. ?>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

¥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="¦a§}" size="5">
½Æ»s¥N½X

TOP

¨Ï¥Î¡uhtmlspecialchars()¡v¨ç¼Æ¨Ó³B²z¡G
  1. <?php
  2. $yaddress = "123</br>123";
  3. $kk = htmlspecialchars($yaddress);
  4. echo $kk;
  5. ?>
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡¦pÆp¥Û¡j®É¶¡¹ï¤@­Ó¦³´¼¼zªº¤H¦Ó¨¥¡A´N¦pÆp¥Û¯ë¬Ã¶Q¡F¦ý¹ï·M¤H¨Ó»¡¡A«o¹³¬O¤@§âªd¤g¡A¤@ÂI»ù­È¤]¨S¦³¡C
ªð¦^¦Cªí ¤W¤@¥DÃD