かんたんな掲示板

お名前:

メッセージ:

sてsて
てsてs
てすと
てすてす
AKIRA
てすと!
ブリジット
あふんn
てす
<xmp>
appare
Today's weather is cloud.
てすと
てすとぅ
test
test
ああ
wwwww
dfdd
aaaaaaiueo
11
111
テスト
テスト
ほくろ毛
ほ毛
hoge
ほ毛
EURO2008
スイス×ポルトガル
hoge
ほげほげほげほげ
ぽっぽっぽ~
testestest
test
testestest
testest
t t t
tt t t ttt
ttt t t t ttttt
tttt t t t t ttttttt
あああ
ああああ
てst
てst
2008
2008
ほげほげ222
げほげほ222
ほげ
ほげ
zzz
zzz
tatatatata
メッセージtatatatatatata
test
<p style="color:red;">テスト</p>
a
a
sdfsd
asdfd
ga-ko
ga-ga-
名無しさん
メッセージー
hhh
hhhh
hhh
hhh
hhh
hhhh
hhh
hhhhh
aaa
aaa
aaa
aaaaa
aaa
aaa
aaa
aaa
aaaaa
aaa
aaa
aaa
aaa
aaa
なまえです
メッセージの1行目
2行目
3行目です
aaaa
hogehoge
ほげほげほげほげほげ
1243
1243
aa
aas
てst
てstだよん
ttt
ttt
テストテスト
どどどどどっど
テスト
テストどど
hoge
hoge
hoge
まいうー
hello
test
田中
テストさせてください
tanaka
tesutoテストテストテストテストテストテストテストテストテスト
a
sss
testname
testarticle
hoge
テストです。
aaa
gggggggg
zzzzzzzaaaaaaaaaaapppppppppppppp
vfds
jhg
test
複数行の
表示は
どうなるのか?
a
b
a
b
fさ
dさあsd
帰りたい
x
マスオです
びゃあ゛ぁ゛うまひぃ゛ぃぃ゛
nama
nana
banana
hogehogehogehogehogehogehogeoge
banana
hogehoge
banana
hoge
ほおいj
ほじょじょ
fsfs
ggdg
てst
テスト
no name
test
test
test
neko
wanwan
mika
thanks
testes
testes
中山
度花弁
tatata
ほげのほげ
a
a
test
テストさせてもらいます
テスト
<br>
<br />
タグりました
あー、本日は晴天なり
本日は晴天なり
俺の戦争はもう終わったんです
俺の戦争はもう終わったんです
ジョン・ランボー
俺の戦争はもう終わったんです
あああああああああああ
あああああああああああ
dou
どう
jjj
あああ
u5e5re
twr5et
hihi
a
a
キムら
てっててテスト
qwerty
ghjkl
a
a
nagumo
test
うがーさん
うがーさん
てst
dadada
dadaada
w
w
test
テストです
K
K
a
a
ほげらもげら
ほげらもげら
lkjhkj
hjjh
test
test
てすと
貼る
テスト太郎
はじめまして。
テストさせてください。
pe40
素晴らしい
てst
<font color="red">test</font>
ほげ
ほげほげ
ほげ・ほげ
なんでもほげ
ほげ
ほげほげ
ほげほげ
hogehoge
yy
hhh
j
jj
j
k
j
gg
ggg

ふがふが
ふらんけんー
てすと
ほげ
ちゃちゃ
んばんばんば
ほげ~
test
test
test
奥村
またまたテスト
ほげ
ほげ
ほげ
おくむら
てすと
ほげほげ

ソース

このページ 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