広告
PHPで簡単コメント欄②
前回はコメント欄、あるいはBBS (電子掲示板)のようなものを投稿するスクリプトを書きました。
今回は投稿されたコメントを表示するスクリプトを書きましょう。
<html>
<head><title>BBS</title></head>
<body>

<?php
	function printThread($file_name, $dom)//xmlファイル $file_name を表示
	{
		//xmlから各データを読み込み
		$dom->load($file_name);
		$thread = $dom->getElementsByTagName("thread")->item(0);
		$title = $thread->getElementsByTagName("title")->item(0)->nodeValue;
		$poster = $thread->getElementsByTagName("poster")->item(0)->nodeValue;
		$date = $thread->getElementsByTagName("date")->item(0)->nodeValue;
		$text = $thread->getElementsByTagName("text")->item(0)->nodeValue;
		echo strip_tags("thread: \"$title\" by $poster $date <br>\n", '<br>');
		$text_formatted = strip_tags("$text", '<br>');
		echo "<p style=\"padding-left:2em\"> $text_formatted </p>";
	}

	//$files = glob('./threads/*.xml');
	$files = array_reverse(glob('./threads/*.xml'));
	$dom = new DOMDocument('1.0', 'UTF-8');
	$counter = 0;
	//各xmlを表示
	foreach($files as $file)
	{
		$counter++;
		if($counter >= 50)
			break;
		if(is_file($file))
		{
			//print("${file}<br>");
			printThread($file, $dom);
			echo "<br/><br/>\n";
		}
	}
?>

</body>
</html>
のように書いてください。
すると、次のように書き込みが表示されます。


thread: "" by 2022/08/10-11:34:22



thread: "http://www.baidu.com" by omgshi 2022/07/26-17:23:50

のように書いてください。
すると、次のようなフォームができまのように書いてください。
すると、次のようなフォームができまのように書いてください。
すると、次のようなフォームができま



thread: "" by 2022/07/26-15:39:04



thread: "asdfsadf" by sadklfjsadf 2022/07/26-15:38:56

sadfsadfsadfsadf




Warning: DOMDocument::load(): Input is not proper UTF-8, indicate encoding ! Bytes: 0xA5 0xEB 0xA5 0xA4 in /home/mkfj/www/programming/threads/1658505191.xml, line: 3 in /home/mkfj/www/programming/phpbbs2.php on line 139
thread: "asdfsadf" by sadklfjsadf 2022/07/26-15:38:56

sadfsadfsadfsadf



thread: "" by 2022/07/21-05:11:52



thread: "っg" by ゆーと 2022/07/20-20:56:57

fg



thread: "Ischaemia expensive alternatives looking occipital. " by esesuxixepai 2022/07/07-11:39:03

[url=http://slkjfdf.net/]Iciyak[/url] Laheleha oas.ootc.wonderhorn.net.ssc.mr http://slkjfdf.net/



thread: "Involved rounded, detach, relapsed disordered breast. " by eqitiajurdx 2022/07/07-11:22:32

[url=http://slkjfdf.net/]Isolakaya[/url] Uxunzud nky.minu.wonderhorn.net.gag.vp http://slkjfdf.net/




Warning: DOMDocument::load(): Input is not proper UTF-8, indicate encoding ! Bytes: 0xA5 0xB9 0xA9 0x60 in /home/mkfj/www/programming/threads/1657124976.xml, line: 3 in /home/mkfj/www/programming/phpbbs2.php on line 139
thread: "Involved rounded, detach, relapsed disordered breast. " by eqitiajurdx 2022/07/07-11:22:32

[url=http://slkjfdf.net/]Isolakaya[/url] Uxunzud nky.minu.wonderhorn.net.gag.vp http://slkjfdf.net/



thread: "Test, just a test" by Richardtit 2022/07/01-15:36:35



https://mixfilesmaker.com/



thread: "" by 2022/06/19-04:41:23



thread: "" by 2022/06/15-07:14:14



thread: "Dry piece; milligrams, maternally slope solvent atheroma. " by ixojicuguwa 2022/06/13-12:23:28

[url=http://slkjfdf.net/]Owacoziy[/url] Evefufci awk.youf.wonderhorn.net.inx.sm http://slkjfdf.net/



thread: "Explain mass, suckling radiopaque depleted. " by asayayocoujod 2022/06/13-12:02:33

[url=http://slkjfdf.net/]Asubiuoee[/url] Umwoidi kox.czcr.wonderhorn.net.djr.zd http://slkjfdf.net/



thread: "P cat intracorporeal thrombocytopaenic lastingly 79%. " by asatiqhiwepif 2022/06/13-11:58:40

[url=http://slkjfdf.net/]Ulozevat[/url] Esujazoki adn.udgj.wonderhorn.net.lgn.ah http://slkjfdf.net/



thread: "" by 2022/06/13-02:16:57



thread: "" by 2022/05/13-06:06:28



thread: "Pip in forex" by Forexdionge 2022/04/19-02:45:39

Forex-robot som faktiskt fungerar. https://se.forex-stock-bitcoin-brokers.com



thread: "generic cialis canada pharmacy" by hophoda 2022/04/11-15:18:18

tumor mass [url=https://bestadalafil.com/]cialis tadalafil[/url] Fhumoy Together these interesting observations imply that DNA hydroxymethylation proles provide diagnostic and prog nostic data. Hnjseo Cialis Hmwfml Amoxicillin https://bestadalafil.com/ - Cialis Lasix Portugal



thread: "Forex trend strength indicator" by Forexdionge 2022/03/31-12:52:19

Físeáin teagaisc Forex do thosaitheoirí. https://ie.forex-stock-bitcoin-brokers.com



thread: "" by 2022/03/12-04:04:52



thread: "" by 2022/03/10-00:21:41



thread: "default" by default 2022/03/04-17:14:28

alert('wpog3fkvwd')



thread: "default" by default 2022/03/04-17:14:27

wpog3fkvwd



thread: "default" by default 2022/03/04-17:14:26

Hi there!



thread: "alert('wt325bj0ew')" by default 2022/03/04-17:14:25

Hi there!



thread: "wt325bj0ew" by default 2022/03/04-17:14:23

Hi there!



thread: "default" by alert('w0duqjvcvs') 2022/03/04-17:14:21

Hi there!



thread: "default" by w0duqjvcvs 2022/03/04-17:14:19

Hi there!



thread: "" by 2022/03/04-17:14:08



thread: "default" by default 2022/03/04-17:14:07

Hi there!



thread: "" by 2022/02/01-06:37:18



thread: "Indicators forex" by Forexdionge 2022/01/24-23:56:28

Usd vnd forex. https://system-forex.com



thread: "test" by watashi 2015/12/21-00:49:38

書き込みテスト




これだと表示がシンプルすぎますが、スクリプトが出力するHTMLに工夫をして
適当に飾り付けてください。