国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

文件內容寫入及讀取

Original 2019-10-07 14:17:58 1709
abstract:<!DOCTYPE html> <html>         <head>                 <

<!DOCTYPE html>

<html>

         <head>

                 <title>create 'txt' file</title>

                 <style type="text/css">

                 *{margin:0;padding: 0;}

                 div{margin: 30px auto;width: 400px;}

                 input{margin: 0 10px;}

                 textarea{width: 400px;height:200px; resize: none;}

                 </style>

         </head>

<body>

                 <div>

                         <form action="samFile.php" method="post">

                                  <p>請輸入文件名:<input type="text" name="fileName"></p>

                                  <p>請輸入文件內容:</p>

                                  <p> <textarea name="content"></textarea> </p>

                                  <input type="submit" name="submit">

                         </form>

                 </div>

            <hr>

             <div>

                         <p class="fileName"></p>

                         <p class="fileContent"></p>

             </div>

</body>

             <script>

                 var fileName=document.getElementsByClassName('fileName').item(0);

                 var fileContent= document.getElementsByClassName('fileContent').item(0);

            </script>

             <?php

                     //獲取請求的文件名

                     @$fileName = $_REQUEST['fileName'];

                     //獲取文件內容

                     @$content = $_REQUEST['content'];

                     //未填文件名,不操作

                     if(!empty($fileName)){

                              //為文件名加入反綴名

                             $fileName=$fileName.'.txt';

                             //創(chuàng)建一個文本文件

                             if(!file_exists($fileName)){

                                             touch($fileName);

                              }

                             //打開文本文件回一個資源

                          $file = fopen($fileName,'a+');

                           //寫入內容

                         fwrite($file,$content."\r\n");

                          //聲明一個空數組,存入字符串

                          $fileStr=[];

                          //文件指針到開頭

                          rewind($file);

                          //讀取文件內容到數組

                         while (!feof($file)) {

                                  //$fileStr[] = fgets($file);

                                 $fileStr[]=fgets($file);

                           }

                         //數組轉字符串變量

                          $str=implode($fileStr);

                         //去掉字符串的換行符

                         $str = preg_replace('/\n|\r\n/','<br>',$str);

                          //內容顯示到頁面上

                          echo "<script>fileName.innerHTML='文件名為: {$fileName}';fileContent.innerHTML='{$str}';</script>";

             }

             ?>

</html>


Correcting teacher:天蓬老師Correction time:2019-10-12 16:29:02
Teacher's summary:OK, 趕緊學習剩下 的課程吧, 加油

Release Notes

Popular Entries