简单留言代码:使用PHP编写留言文本框

 编写一个程序实现留言的文本框,所写代码如下:

<?Phpheader('Content-Type:text/html;charset=utf8');date_default_timezone_set('PRC');@$string = file_get_contents('message.txt');if (!empty($string)) { $string = rtrim($string, '&^'); $arr = explode('&^', $string); foreach ($arr as $value) { list($username, $content, $time) = explode('$#', $value); echo '用户名为<font color="gree">' . $username; echo '</font>内容为<font color="blue">' . $content; echo '</font>时间为' . date('Y-m-d H:i:s', $time); echo '<hr />'; }}?><h1>文件留言本演示</h1><form action="write.php" method="post"> 用户:<input type="text" name="username" /><br /> 留言:<textarea name="content"></textarea><br /> <input type="submit" value="提交" /></form>

 会出现如下界面:

 

 输入信息并提交的代码如下:

<?php$fp=fopen('message.txt','a');$time=time();$username=trim($_POST['username']);$content=trim($_POST['content']);$string=$username.'$#'.$content.'$#'.$time.'&^';fwrite($fp,$string);fclose($fp);header('location:index.php');?>

 会出现如下界面

 在messages文本内会出现留言信息如下:

 

相关推荐

相关文章