溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 101-2資管二甲丙教學資源區 - 第十週Textarea與留言版
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

第十週Textarea與留言版

<?php
   // 檔案操作
   $fp=fopen("test.txt","w");        // 開啟檔案 寫入
   for ($i=1; $i<=100; $i++) {   
     fputs($fp,$i);                          // 寫入檔案
     fputs($fp,"\n");                       // 跳列
   }
   fclose($fp);                              // 關檔
   $fp=fopen("test.txt","r");       // 開檔  輸入
   while ($line=fgets($fp))  {    // 讀入檔案,每次一列
     echo $line;                           // 顯示於瀏覽器
     echo "<br>";                        // 跳列
   };
   fclose($fp);                            // 關檔
?>


<?php
 // 留言板
  $command=$_POST["command"];
  if ($command==null)  {
     echo("<html>
               <body>
               <center>
               <form method=post action=$SELF_PHP>
               留言版: <p>
               <textarea name='note' rows=3 cols=40 wrap=physical>
               </textarea>
               <p>
              <input type=submit name=command value=送出>
              <input type=reset  name=command value=清除>
            </form>
            </center>
            </body>
            </html>");
  }
  if ($command=="送出") {
    $note=$_POST["note"];
    $note = str_replace("\n", "<br>", $note);
    echo("<html>
               <body>
               <center>
               留言: <p> $note
               </center>
              </body>
             </html>");
  }
?>

 作業:利用前述兩個範例, 寫一個留言版, 將留言內容寫入一個檔案

 

全部共 0則留言
登入帳號密碼代表遵守學術網路規範
 


文章分類 Labels

 


最新文章 Top10

中華科技大學數位化學習歷程 - 意見反應