<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
if($_REQUEST['action']=='do'){
extract($_POST);
$r=fopen('post.txt','a+');
$str=iconv('utf-8','gb2312',$T1.' '.$R1.' '.$T2.' '.$S1."<br>");
fwrite($r,$str);
echo '<script>location.href="index.php";</script>';
}
if(file_exists('post.txt')){
$result=explode("<br>",substr(iconv('gb2312','utf-8',file_get_contents('post.txt')),0,-4));
foreach ($result as $value){
$arr=explode(" ",$value);
$postarr[]=$arr;
}
}
><?php if(count($result)):?>
<?php foreach ($postarr as $value):?>
name:<?php echo $value[0];?><br>
sex:<?php if($value[1])echo 'female';else echo 'male';?><br>
email:<?php echo $value[2];?><br>
message:<?php echo $value[3];?><br>
<hr>
<?php endforeach;?>
<?php else:?>
沒有留言
<?php endif;?>
<form method="post" action="index.php?action=do">
<p>Your name: <input type="text" name="T1"/></p>
<p>Sex:
Male<input type="radio" value="0" name="R1"/>
Female<input type="radio" name="R1" value="1"/></p>
<p>Your email: <input type="text" name="T2" size="35"/></p>
<p>Your massage:</p>
<p> <textarea rows="16" name="S1" cols="44"></textarea></p>
<p><input type="submit" value="Submit" name="B1"/>
<input type="reset" value="Reset" name="B2"/></p>
</form>
</body>
</html>