Harigami
ログイン
anonymous タイトルなし
No License PHP
コピー
<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="UTF-8">
        <title>Mission_3-4</title>
    </head>
    <body>
        <?php
        $filename="Mission_3-4.txt";
        $name=$_POST["name"];
        $str=$_POST["str"];
        $number=$_POST["number"];
        $delete=$_POST["delete"];
        $edit=$_POST["edit"];
        $date=date("Y年m月d日H時i分s秒");
        if(file_exists($filename))
        {$number=count(file($filename))+1;}
        else{$number=1;}
        
        $out=$number."<>".$name."<>".$str."<>"
        .$date.PHP_EOL;
        
        /*コメントフォーム*/
        
        if(!empty($name)&&!empty($str)){
        
        $fileopen=fopen($filename,"a");
        fwrite($fileopen,$out);
        fclose($fileopen);
        
        
        $contents=file($filename,FILE_IGNORE_NEW_LINES);
        foreach($contents as $content){
        $explode=explode("<>",$content);
        echo $explode[0],"",$explode[1],"",
             $explode[2],"",$explode[3]."<br>";
            
        }}
        elseif(!empty($name)&&!empty($str)&&!empty($number))
        
        {$contents=file($filename,FILE_IGNORE_NEW_LINES);
        $fileopen=fopen($filename,"w");
        foreach($contents as $content){
        $explode=explode("<>",$content);
        
        if($edit==$explode[0]){
        
        fwrite($fileopen,$explode[0]."<>".$explode[1]."<>".
        $explode[2]."<>".$explode[3].PHP_EOL);
        
        
        }}}
            
        
       
       
       
       if(!empty($delete)){
           $contents=file($filename,FILE_IGNORE_NEW_LINES);
           $fileopen=fopen($filename,"w");
           foreach($contents as $content){
               $explode=explode("<>",$content);
        
        if($delete!=$explode[0]){
            fwrite($fileopen,$explode[0]."<>".$explode[1]."<>".
        $explode[2]."<>".$explode[3].PHP_EOL);
        
        
        echo $explode[0],"",$explode[1] 
                ,"",$explode[2],"",
                $explode[3]."<br>";   
               
               
           }
           
       }
       }

 
     if(!empty($edit)){
    $contents=file($filename,FILE_IGNORE_NEW_LINES);
    foreach($contents as $content){
    $explode_edit=explode("<>",$content);
    
    $explode_number=$explode_edit[0];
    if($explode_number==$edit){
        $explode_name=$explode_edit[1];
        $explode_str=$explode_edit[2];
        
    }
    }
 }
 
 
 
 
        ?>
        <!--コメントフォーム-->
        <form action="" method="post">
            <input type="text" name="number" 
            placeholder="編集番号" value="<?php echo $edit;?>"> 
            <input type="text" name="name" 
            placeholder="名前" value="<?php echo $explode_name;?>">
            <input type="text" name="str" 
            placeholder="コメント" value="<?php echo $explode_str;?>">
            <input type="submit" name="submit">
        <!--削除フォーム-->
            <input type="削除番号" name="delete" 
            placeholder="削除番号">
            <input type="submit" name="submit_delete" 
            value="削除">
        <!--編集フォーム-->
        <input type="text" name="edit" 
            placeholder="編集対象番号">
            <input type="submit" name="submit_edit" 
            value="編集">
        </form>
        
        
    </body>
</html>
<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="UTF-8">
        <title>Mission_3-4</title>
    </head>
    <body>
        <?php
        $filename="Mission_3-4.txt";
        $name=$_POST["name"];
        $str=$_POST["str"];
        $number=$_POST["number"];
        $delete=$_POST["delete"];
        $edit=$_POST["edit"];
        $date=date("Y年m月d日H時i分s秒");
        if(file_exists($filename))
        {$number=count(file($filename))+1;}
        else{$number=1;}
        
        $out=$number."<>".$name."<>".$str."<>"
        .$date.PHP_EOL;
        
        /*コメントフォーム*/
        
        if(!empty($name)&&!empty($str)){
        
        $fileopen=fopen($filename,"a");
        fwrite($fileopen,$out);
        fclose($fileopen);
        
        
        $contents=file($filename,FILE_IGNORE_NEW_LINES);
        foreach($contents as $content){
        $explode=explode("<>",$content);
        echo $explode[0],"",$explode[1],"",
             $explode[2],"",$explode[3]."<br>";
            
        }}
        elseif(!empty($name)&&!empty($str)&&!empty($number))
        
        {$contents=file($filename,FILE_IGNORE_NEW_LINES);
        $fileopen=fopen($filename,"w");
        foreach($contents as $content){
        $explode=explode("<>",$content);
        
        if($edit==$explode[0]){
        
        fwrite($fileopen,$explode[0]."<>".$explode[1]."<>".
        $explode[2]."<>".$explode[3].PHP_EOL);
        
        
        }}}
            
        
       
       
       
       if(!empty($delete)){
           $contents=file($filename,FILE_IGNORE_NEW_LINES);
           $fileopen=fopen($filename,"w");
           foreach($contents as $content){
               $explode=explode("<>",$content);
        
        if($delete!=$explode[0]){
            fwrite($fileopen,$explode[0]."<>".$explode[1]."<>".
        $explode[2]."<>".$explode[3].PHP_EOL);
        
        
        echo $explode[0],"",$explode[1] 
                ,"",$explode[2],"",
                $explode[3]."<br>";   
               
               
           }
           
       }
       }

 
     if(!empty($edit)){
    $contents=file($filename,FILE_IGNORE_NEW_LINES);
    foreach($contents as $content){
    $explode_edit=explode("<>",$content);
    
    $explode_number=$explode_edit[0];
    if($explode_number==$edit){
        $explode_name=$explode_edit[1];
        $explode_str=$explode_edit[2];
        
    }
    }
 }
 
 
 
 
        ?>
        <!--コメントフォーム-->
        <form action="" method="post">
            <input type="text" name="number" 
            placeholder="編集番号" value="<?php echo $edit;?>"> 
            <input type="text" name="name" 
            placeholder="名前" value="<?php echo $explode_name;?>">
            <input type="text" name="str" 
            placeholder="コメント" value="<?php echo $explode_str;?>">
            <input type="submit" name="submit">
        <!--削除フォーム-->
            <input type="削除番号" name="delete" 
            placeholder="削除番号">
            <input type="submit" name="submit_delete" 
            value="削除">
        <!--編集フォーム-->
        <input type="text" name="edit" 
            placeholder="編集対象番号">
            <input type="submit" name="submit_edit" 
            value="編集">
        </form>
        
        
    </body>
</html>
コンソール
現在、コメントはありません。
他の人よりも先にコメントしましょう。