anonymous No title
No License PHP
2021年02月23日
Copy Clone
<html>
<form action="" method="Post">
<head><title>mission_3-3</title></head>
        <input type="comment" name="com" placeholder=
        "コメント">
        <input type="submit" name="submit">
        <body><br><br></body>
<input type="number" name="num" placeholder="削除する番号">
<input type="submit" name="delete" value="削除"> 
</form>
<?php
$com=$_POST["com"];
$num=$_POST["num"];
//ファイルの読み込み
$filename="mission_3-3.txt";
if(file_exists($filename)){
$fq=fopen($filename,"r");
$txt = fgets($fq);
foreach($txt as $line){
$a=explode("<>",$line);
}
fclose($fq);
}

//削除
if(empty($num));
else{
$fp=fopen($filename,"w");
foreach($a as $line2){
     if($line2=$a[$num]);
     else{fwrite($fp,$a.PHP_EOL);}
}
}
fclose($fp);

//コメントの追加
if(empty($com));
else{
$fp1=fopen($filename,"a");
fwrite($fp1,$com.PHP_EOL);
fclose($fp1);
}
?>
</html>
<html>
<form action="" method="Post">
<head><title>mission_3-3</title></head>
        <input type="comment" name="com" placeholder=
        "コメント">
        <input type="submit" name="submit">
        <body><br><br></body>
<input type="number" name="num" placeholder="削除する番号">
<input type="submit" name="delete" value="削除"> 
</form>
<?php
$com=$_POST["com"];
$num=$_POST["num"];
//ファイルの読み込み
$filename="mission_3-3.txt";
if(file_exists($filename)){
$fq=fopen($filename,"r");
$txt = fgets($fq);
foreach($txt as $line){
$a=explode("<>",$line);
}
fclose($fq);
}

//削除
if(empty($num));
else{
$fp=fopen($filename,"w");
foreach($a as $line2){
     if($line2=$a[$num]);
     else{fwrite($fp,$a.PHP_EOL);}
}
}
fclose($fp);

//コメントの追加
if(empty($com));
else{
$fp1=fopen($filename,"a");
fwrite($fp1,$com.PHP_EOL);
fclose($fp1);
}
?>
</html>
No one still commented. Please first comment.
Output