php结合html小案例

index.php文件代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>评论</title>
</head>
<body>
<h3  style="text-align: center">留言列表</h3>
	<form action="jump.php" method="post">
	<input type="hidden" name="act"  value="add"/>
	   <table style="margin:auto;" border="1px solid black" width="1100px"   bgcolor="#64bff2">
	   	
	   	<tr>
	   		<td>留言者</td>
	   		<td><input type="text" name="user" /></td>
	   	</tr>
	   	<tr>
	   		<td>标题</td>
	   		<td><input type="text" name="topic" /></td>
	   	</tr>
	   	<tr>
	   		<td>内容</td>
	   		<td><textarea name="content" id="content" cols="30" rows="10"></textarea></td>
	   	</tr>
	   	<tr>
	   		<td>心情</td>
	   		<td height="50px">
	   		<input type="radio" name="xinqing" value="qw_cat_0001.gif" checked="checked"/><img height="150" width="150" src="img/qw_cat_0001.gif" alt="膝盖中箭" />
	   		<input type="radio" name="xinqing" value="qw_cat_0002.gif" /><img height="150" width="150" src="img/qw_cat_0002.gif" alt="我察" />
	   		<input type="radio" name="xinqing" value="qw_cat_0003.gif" /><img height="150" width="150" src="img/qw_cat_0003.gif" alt="你懂的" />
	   		<input type="radio" name="xinqing" value="qw_cat_0004.gif" /><img height="150" width="150" src="img/qw_cat_0004.gif" alt="这真是极好的" />
	   		<input type="radio" name="xinqing" value="qw_cat_0005.gif" /><img height="150" width="150" src="img/qw_cat_0005.gif" alt="给力" />
	   		
	   		</td>
	   	</tr>
	   	<tr>
	   		<td colspan="2" style="padding-left:200px;padding:auto;">
	   		  <input type="submit" value="提交" style="width:50px;height:30px;" />
	   		  <input type="reset" value="重置" style="width:50px;height:30px;"/>
	   		</td>
	   	</tr>
	   </table>
	</form>
</body>
</html>

</html>


jump.php文件代码:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>Document</title>
</head>
<?php
$act= isset($_POST['act'])?$_POST['act']:'';
$user= isset($_POST['user'])?$_POST['user']:'';
$topic= isset($_POST['topic'])?$_POST['topic']:'';
$content= isset($_POST['content'])?$_POST['content']:'';
$xinqing= isset($_POST['xinqing'])?$_POST['xinqing']:'';
$time=date('Y-m-d h:i:s');
$filename='text.txt';
$arr=array();
if(file_exists($filename)&&filesize($filename)>0){
    $str=file_get_contents($filename);
    $arr=unserialize($str);
}
if($act=='add'){
    $arr[] =array(
        'user'=>$user,
        'topic'=>$topic,
        'content'=>$content,
        'xinqing'=>$xinqing,
        'time'=>$time
    );
//     print_r($arr);
    $arr=serialize($arr);//将数组序列化
    //a:4:{s:4:"user";s:6:"小明";s:5:"topic";s:9:"留言板";s:7:"content";s:12:"去哪里?";s:7:"xinqing";s:15:"qw_cat_0002.gif";}
    //a表示array数组,4表示数组大小,{}数组内容,里面以分号;隔开。
    //内容中: s表示类型,4表示值大小,冒号:后是值(注意,一个汉字字符占3个)
    file_put_contents($filename,$arr);
    $str=file_get_contents($filename);
    $arr=unserialize($str);
}

?>
<body>
<h3 style="text-align: center">评论列表</h3>
	<table style="margin:auto;" border="1px solid black" width="1100px" bgcolor="#64bff2">
		<tr>
			<th>名称</th>
			<th>话题</th>
			<th>内容</th>
			<th>心情</th>
			<th>时间</th>
		</tr>
		<?php 
		  foreach ($arr as $key => $value){
		      echo '<tr height="80px"  style="text-align: center;">';
		      /* foreach ($value as $key2 => $value2){
		          echo '<td>'.$value2.'</td>';
		      } */
		      echo '<td>'.$value['user'].'</td>';
		      echo '<td>'.$value['topic'].'</td>';
		      echo '<td>'.$value['content'].'</td>';
		      echo '<td><img height="100" width="100" src="img/'.$value['xinqing'].'" alt="你懂的" /></td>';
		      echo '<td>'.$value['time'].'</td>';
		      
		      echo '</tr>';
		  }
		
		?>
	</table>
</body>
</html>


工程结构:



访问页面效果:


跳转后:



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值