- <!DOCTYPE html>
- <html lang = "ja">
- <head>
- <meta charset="UTF-8">
- <title>mission3</title>
- </head>
- <body>
- <form action="" method="post">
- <input type="text" name="name" placeholder="名前">
- <input type="text" name="comment" placeholder="コメント">
- <input type="submit" name="submit">
- <form action="" method="post">
- <input type="number" name="delete" placeholder="削除対象番号" >
- <input type="submit" name="submit" value="削除">
- </form>
- </form>
-
- <?php
-
- $str = $_POST["str"];
- $name = $_POST["name"];
- $del = $_POST["del"];
- if(empty($str.$name)){
- }else{
-
- $filename="mission3-3.txt";
- $fp=fopen($filename,"a");
- $date = date("Y年m月d日H時i分s秒");
- $num = count(file($filename));
- $num++;
- fwrite($fp,$num."<>".$name."<>".$str."<>".$date.PHP_EOL);
- fclose($fp);
- }
-
-
-
-
-
-
-
- //削除
- if(empty($delete)){
- }else{
- $lines=file($filename,FILE_IGNORE_NEW_LINES);
- $fp=fopen($filename,"w");
- foreach($lines as $line){
- $line=explode("<>",$line);
- if($delete!= $line[0]){
- fwrite($fp,$line[0]."<>".$line[1]."<>".$line[2]."<>".$line[3].PHP_EOL);
-
- } //echo $explode[0],"",$explode[1],"",$explode[2],"",$explode[3]."<br>";
- //$fp=fopen($filename,"a");
- //$txt=$form[0]."<>".$form[1]."<>".$form[2]."<>".$form[3].PHP_EOL;
- // fwrite($fp,$txt);
- }fclose($fp);
- }
-
-
- //画面表示
- if(file_exists($filename)){
- $lines=file($filename,FILE_IGNORE_NEW_LINES);
- foreach($lines as $line){
- $line=explode("<>",$line);
- echo $line[0]."";
- echo $line[1]."";
- echo $line[2]."";
- echo $line[3]."<br>";
- }
- }
-
- ?>
- </body>
-
- </html>
参考にしたサイト