$message = 'Hello World'; if($_POST["article"]){ $article = htmlspecialchars($_REQUEST['article']); $name = htmlspecialchars($_REQUEST['name']); $line = $article . '(' . $name . ')' . PHP_EOL; file_put_contents(__DIR__ . '/articles.txt', $line, FILE_APPEND | LOCK_EX); } $lines = file(__DIR__ . '/articles.txt', FILE_IGNORE_NEW_LINES); require_once 'bbs.tpl.php';
h1>1行掲示板/h1> p>?= $message ?>/p> form action='bbs2.php' method='post'> label for='article'>投稿/label> input type='text' name='article'> label for='name'>名前/label> input type='text' name='name'> button type='submit'>送信する/button> /form> h2>投稿一覧/h2> ?php foreach ($lines as $line) { ?> p>?= $line ?>/p> ?php } ?>