anonymous No title
PHP
<?php

define( 'FILENAME', 'kadai_2_3(2).txt');

date_default_timezone_set('Asia/Tokyo');

$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();


if( !empty($_POST['btn_submit']) ) {
	
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
		if (file_exists($filename)) {
   		 $num = count(file($filename))+1;
		} else {
    			$num = 1;
		}
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date.;

	
		fwrite( $file_handle, $data);
	
		fclose( $file_handle);
	}		
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
	
		$split_data = preg_split( '/\'/', $data);
		
		$message = array(
			'view_name' => $split_data[1],
			'message' => $split_data[3],
			'post_date' => $split_data[5]
		);
		array_unshift( $message_array, $message);
	}
	
	fclose( $file_handle);
}

?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<?php
define( 'FILENAME', 'kadai_2_3(2).txt');
date_default_timezone_set('Asia/Tokyo');
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();

if( !empty($_POST['btn_submit']) ) {
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
  		$num=count(file($filename));
		$num++;
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."'\n";
		fwrite( $file_handle, $data);
		fclose( $file_handle);	
	}	
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
		$split_data = preg_split( '/\'/', $data);
        	$message = array(
            	'view_name' => $split_data[1],
            	'message' => $split_data[3],
            	'post_date' => $split_data[5]
        	);
        	array_unshift( $message_array, $message);
    }
	fclose( $file_handle);

?>


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<?php
define( 'FILENAME', 'kadai_2_3(2).txt');
date_default_timezone_set('Asia/Tokyo');
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();

if( !empty($_POST['btn_submit']) ) {
	if( $file_handle = fopen( FILENAME, "a") ) {
		$now_date = date("Y-m-d H:i:s");
  		$num=count(file($filename));
		$num++;
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."'\n";
		fwrite( $file_handle, $data);
		fclose( $file_handle);	
	}	
}

if( $file_handle = fopen( FILENAME,'r') ) {
	while( $data = fgets($file_handle) ){
		$split_data = preg_split( '/\'/', $data);
        	$message = array(
            	'view_name' => $split_data[1],
            	'message' => $split_data[3],
            	'post_date' => $split_data[5]
        	);
        	array_unshift( $message_array, $message);
    }
	fclose( $file_handle);
}
?>


<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>
<body>
<h1>簡易掲示板</h1>
<form method="post">
	<div>
		<label for="view_name">名前</label>
		<input id="view_name" type="text" name="view_name" value="">
	</div>
	<div>
		<label for="message">コメント</label>
		<textarea id="message" name="message"></textarea>
	</div>
	<input type="submit" name="btn_submit" value="送信">
</form>
<hr>
<section>
<?php if( !empty($message_array) ): ?>
<?php foreach( $message_array as $value ): ?>
<article>
    <div class="info">
        <h2><?php echo $value['view_name']; ?></h2>
        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
    </div>
    <p><?php echo $value['message']; ?></p>
</article>
<?php endforeach; ?>
<?php endif; ?>
</section>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_4 php</title>
</head>
<body>
<form action = "kadai_4.php" mothod = "get">
	<input type = "text" name ="sendtext"><br/>
	<input type ="submit" valude ="送信">
</form>
<?php
	echo "入力されたテキストが下に表示されます<br/>";
	if(isset($_GET["sendtext"])){
		echo $_GET["sendtext"];
	}
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_3 php</title>
</head>
<body>
<?php
echo file_get_contents("saveDoc.txt");
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_1_2 php</title>
</head>
<body>
<?php
$text = "Kadai_1_2 test OK!";
echo "<p>"."$text"."</p>";
echo '<p>Hello World!</p>';
$fp = fopen("saveDoc.txt","w");
fwrite($fp,"$text");
fclose($fp);
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html>
<head>
<title>kadai_1 php</title>
</head>
<body>
<?php
$text = "Kadai_1";
echo '<p>Hello World!</p>';
?>
</body>
</html>
anonymous No title
PHP
<!DOCTYPE html>
<html lang="ja" >
  <head>
    <meta charset="UTF-8">
    <title>簡易掲示板</title>
  </head>
  <body>
  <h1>簡易掲示板</h1>
    <form method="post" action="" >
      <p>名前</p>
      <input type="text" name="user_name" required>
      <p>コメント</p>
      <textarea name="comment" rows="4" cols="40"></textarea><br>
      <input type="submit" value="送信">
    </form>
    <?php
   	error_reporting(0);
    	$name=$_POST["user_name"];
   	$comment=$_POST["comment"];
   	$today = date("Y-m-d H:i:s");
   	$filename="kadai_2_2.txt";
   	$num=count(file($filename));
	$num++;
   	fwrite($fp, $num . '<>' . $name . '<>' . $comment . '<>' . $date . "\n");
     	fclose($fp);
    ?>
  </body>
</html>
anonymous No title
PHP
<?php
echo "パスワード、編集番号、削除番号は全て半角で入力してください";
$text_file = "kadai_2_6.txt";
$count_file = "kadai_2_6count.txt";
$date = date("Y-m-d");
$edit_form_number = "";
$edit_form_name = "";
$edit_form_comment = "";
$edit_form_password = "";
if (!empty($_POST["submit_edit"])) {
  $text_file_array_edit = file($text_file);
  $edit_number = $_POST["edit_number"];
  $edit_password = $_POST["edit_password"];
  foreach ($text_file_array_edit as $edit_value) {
    $edit_value_explode = explode("<>",$edit_value);
    if ($edit_value_explode[0] == $edit_number && $edit_value_explode[1] == $edit_password) {
      $edit_form_number = $edit_value_explode[0];
      $edit_form_name = $edit_value_explode[2];
      $edit_form_comment = $edit_value_explode[3];
      $edit_form_password = $edit_value_explode[1];
    }
  }
}
if (!empty($_POST["submit_normal"])) {
  $normal_name = $_POST["normal_name"];
  $normal_comment = $_POST["normal_comment"];
  $normal_password = $_POST["normal_password"];
  $fp = fopen($count_file,"r");
  $count = fgets($fp);
  fclose($fp);
  $count+=1;
  $fp = fopen($count_file,"w");
  fwrite($fp,$count);
  fclose($fp);
  $text_contents_normal = $count . "<>" . $normal_password . "<>" . $normal_name . "<>" . $normal_comment . "<>" . $date . "\n";
  $fp = fopen($text_file,"a");
  fwrite($fp,$text_contents_normal);
  fclose($fp);
  if (!empty($_POST["edit_hidden"])) {
    $text_file_array_edit_contents = file($text_file);
    $edit_hidden = $_POST["edit_hidden"];
    foreach ($text_file_array_edit_contents as &$text_contents_edit) {
      $text_contents_edit_explode = explode("<>",$text_contents_edit);
      if ($text_contents_edite_xplode[0] == $edit_hidden) {
        $text_contents_edit = $edit_hidden . "<>" . $normal_password . "<>" . $normal_name . "<>" . $normal_comment . "<>" . $date . "\n";
      }
    }
    $fp = fopen($text_file,"w");
    fwrite($fp,$text_file_array_edit_contents);
    fclose($fp);
  }
}
if (!empty($_POST["submit_delete"])) {
  $text_file_array_delete = file($text_file);
  $delete_number = $_POST["delete_number"];
  $delete_password = $_POST["delete_password"];
  $text_contents_delete = [];
  foreach ($text_file_array_delete as $delete_value) {
    $delete_value_explode = explode("<>",$delete_value);
    if ($delete_value_explode[0] == $delete_number && $delete_value_explode[1] == $delete_password) {
      continue;
    }else{
      $text_contents_delete[] = $delete_value;
    }
  }
  $fp = fopen($text_file,"w");
  fwrite($fp,implode("",$text_contents_delete));
  fclose($fp);
}
 ?>
 <!DOCTYPE html>
 <html lang="ja">
   <head>
     <meta charset="utf-8">
     <title>簡易掲示板</title>
   </head>
   <body>
     <h1>簡易掲示板</h1>
     <form action="kadai_2_6.php" method="post">
       <input type="hidden" name="edit_hidden" value="<?php echo $edit_form_number; ?>">
       名前:<input type="text" name="normal_name" value="<?php echo $edit_form_name; ?>"><br>
       コメント:<input type="text" name="normal_comment" value="<?php echo $edit_form_comment; ?>"><br>
       パスワード:<input type="text" name="normal_password" value="<?php echo $edit_form_password; ?>"><br>
       <input type="submit" name="submit_normal" value="投稿">
    </form>
    <h1>削除フォーム</h1>
    <form action="kadai_2_6.php" method="post">
      削除番号:<input type="text" name="delete_number"><br>
      パスワード:<input type="text" name="delete_password"><br>
      <input type="submit" name="submit_delete" value="削除する">
    </form>
    <h1>編集フォーム</h1>
    <form action="kadai_2_6.php" method="post">
      編集番号:<input type="text" name="edit_number"><br>
      パスワード:<input type="text" name="edit_password"><br>
      <input type="submit" name="submit_edit" value="編集する">
    </form>
    <?php
     $text_file_array_display = file($text_file);
     foreach ($text_file_array_display as $display_value) {
       $display_value_explode = explode("<>",$display_value);
       echo $display_value_explode[0] . " " . $display_value_explode[2] . " " . $display_value_explode[3] . " " . $display_value_explode[4] . "<br>";
     }
     ?>
   </body>
 </html>
anonymous No title
PHP
<?php
    $filename = "kadai_2_5.txt";
    $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $editNumber = '';
    $editName = '';
    $editComment = '';
    if(isset($_POST["edit"])) {
        foreach($lines as $row) {
            $bbsRowData = explode("<>", $row);
            if($bbsRowData[0] == $_POST["number"]) {
                $editNumber = $bbsRowData[0];
                $editName = $bbsRowData[1];
                $editComment = $bbsRowData[2];
                break;
            }
        }
    }
    else if(isset($_POST["normal"])) {
        $now_date=date("Y-m-d");
        $writeData = ($_POST['edit_post'] ?: count($lines) + 1) . "<>" . $_POST['name'] . "<>" . $_POST['comment'] . "<>" . $now_date;
        if($_POST["edit_post"]) {
            foreach($lines as &$row) {
                $bbsRowData = explode("<>", $row);
                if($bbsRowData[0] == $_POST["edit_post"]) {
                    $row = $writeData;
                }
            }
        }
        else {
            $lines[] = $writeData;
        }
     file_put_contents($filename, implode("\n", $lines));
    }
?>
<!doctype html>
<html lang="ja">
 <head>
  <meta charset="UTF-8">
  <title>簡易掲示板</title>
 </head>
 <body>
  <h1>簡易掲示板</h1>
  <form action="kadai_2_5.php" method="POST">
   <input type="hidden" name="edit_post" value="<?php echo $editNumber; ?>">
   名前:<input type="text" name="name" value="<?php echo $editName; ?>">
   <br />
   コメント:<input name="comment" value="<?php echo $editComment; ?>">
   <br />
   <input type="submit" name="normal" value="送信">
  </form>
  <h1>編集用フォーム</h1>
  <form action="kadai_2_5.php" method="POST">
   編集番号:<input type="text" name="number">
   <input type="submit" name="edit" value="送信">
  </form>
  <?php
  $ret_array=file($filename);
  foreach ($ret_array as $value) {
    $file_array=explode("<>",$value);
    foreach ($file_array as $value_array) {
      echo($value_array."<br />\n");
    }
  }
   ?>
 </body>
</html>
Don't you submit code?
Submit