anonymous No title
No License PHP
2020年10月25日
Copy
<?php
    $filename = "kadai_2-2.txt";
    if(isset($_POST["name"]) && isset($_POST["comment"])) {
      $name = $_POST["name"];
      $comment = $_POST["comment"];



      if (empty($name)) {
        $name = "名無し";
      }
      
      $fp = fopen($filename, "a");
      fwrite($fp, count(file($filename))+1);   
      fwrite($fp, "<>");
      fwrite($fp, $name."<>");
      fwrite($fp, $comment."<>");
      fwrite($fp, date("Y-m-d H:i:s")."\n");
      fclose($fp);
?>

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-3</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form action = "kadai_2-3.php" method = "post" >
    <p>名前</p>
    <input type = "text" name = "name" >
    <p>コメント</p>
    <textarea name = "comment" ></textarea><br>
    <input type = "submit" value = "投稿"><br>
  </form>

  
    <?php
      $ret_array = file($filename);
      $reverse = array_reverse($ret_array);
      
        for($i = 0; $i < count($reverse); $i++) {

          echo $reverse[$i]."<br><br>";
      }
    }
  ?>

</body>
</html>
<?php
    $filename = "kadai_2-2.txt";
    if(isset($_POST["name"]) && isset($_POST["comment"])) {
      $name = $_POST["name"];
      $comment = $_POST["comment"];



      if (empty($name)) {
        $name = "名無し";
      }
      
      $fp = fopen($filename, "a");
      fwrite($fp, count(file($filename))+1);   
      fwrite($fp, "<>");
      fwrite($fp, $name."<>");
      fwrite($fp, $comment."<>");
      fwrite($fp, date("Y-m-d H:i:s")."\n");
      fclose($fp);
?>

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>課題2-3</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form action = "kadai_2-3.php" method = "post" >
    <p>名前</p>
    <input type = "text" name = "name" >
    <p>コメント</p>
    <textarea name = "comment" ></textarea><br>
    <input type = "submit" value = "投稿"><br>
  </form>

  
    <?php
      $ret_array = file($filename);
      $reverse = array_reverse($ret_array);
      
        for($i = 0; $i < count($reverse); $i++) {

          echo $reverse[$i]."<br><br>";
      }
    }
  ?>

</body>
</html>

Output

Run
年末年始は機械学習・深層学習を勉強しませんか?
No one still commented. Please first comment.
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら