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

5-6-3 ¦h¦æ¤å¦r¿é¤J¤¸¥ó¡]Textarea¡^

5-6-3 ¦h¦æ¤å¦r¿é¤J¤¸¥ó¡]Textarea¡^

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

§Ú­Ì±`¦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½d¨Òex5_14.php
  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

¦³®É­Ô¡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
½d¨Òtextarea_2_ans.php°õ¦æ«á¡A¦p¤U¹Ï¡A½Ð°t¦Xtextarea_2.phpªí³æ¿é¤Jºô­¶¡G

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

TOP

¥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

¹Ï5-23  ¦h¦æ¤å¦r¿é¤J¤¸¥ó¡C
textarea_ans.php
  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

¹Ï5-24  ¨Ï¥Î¡unl2br()¡v¨ç¼ÆÅܧ󴫦æ²Å¸¹¬°HTML¼ÐÅÒ¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : °µ¸Ó°µªº¨Æ¬O´¼¼z¡A°µ¤£¸Ó°µªº¨Æ¬O·Mè¡C
ªð¦^¦Cªí ¤W¤@¥DÃD