かんたんな掲示板
例
|
appare |
|
Today's weather is cloud. |
|
testestest |
test testestest testest t t t tt t t ttt ttt t t t ttttt tttt t t t t ttttttt |
|
tatatatata |
|
メッセージtatatatatatata |
|
test |
|
<p style="color:red;">テスト</p> |
|
tanaka |
|
tesutoテストテストテストテストテストテストテストテストテスト |
|
gggggggg |
|
zzzzzzzaaaaaaaaaaapppppppppppppp |
|
banana |
|
hogehogehogehogehogehogehogeoge |
|
test |
テストさせてもらいます テスト <br> <br /> タグりました あー、本日は晴天なり 本日は晴天なり |
|
てst |
|
<font color="red">test</font> |
ソース
このページ bbs.html には次のように書いておくだけです。
<form action="bbswrite.php" method="post">
<p>お名前:<input name="name" size="20" /></p>
<p>メッセージ:<br />
<textarea name="message" rows="5" cols="60"></textarea></p>
<p>
<input type="submit" value="送る" />
<input type="reset" value="クリア" />
</p>
</form>
<!-- BEGIN -->
「送る」を押すと呼び出される bbswrite.php には次のように書いておきます。
<?php
if ($_POST['name'] != '' && $_POST['message'] != '') {
echo "<h1>書き込みました</h1>\n";
$f1 = fopen("bbs.html", "r");
$f2 = fopen("bbs2.html", "w");
while (!feof($f1)) {
$buf = fgets($f1, 4096);
fwrite($f2, $buf);
if (strncmp($buf, "<!-- BEGIN -->", 14) == 0) {
fwrite($f2, "<table width=\"100%\" border=\"1\"><tr><td>\n");
fwrite($f2, htmlspecialchars($_POST['name']));
fwrite($f2, "</td></tr><tr><td>\n");
fwrite($f2, preg_replace('/[\r\n]+/', '<br />', htmlspecialchars($_POST['message'])));
fwrite($f2, "</td></tr></table>\n");
}
}
fclose($f1);
fclose($f2);
copy("bbs2.html", "bbs.html");
} else {
echo "<h1>名前・メッセージが空です</h1>\n";
}
?>
あとは bbs2.html というファイル(内容は何でもよい)も作っておき,bbs.html,bbs2.html
のパーミッションは 666 にしておきます。
古いものを自動的に消すなどの機能は自分で考えてください。^^;
奥村晴彦
Last modified: 2008-04-13 12:41:45