Home > php教程 > php手册 > 仿网易163新闻评论盖楼效果代码

仿网易163新闻评论盖楼效果代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:23:35
Original
939 people have browsed it

仿网易163新闻评论盖楼效果代码

//发送留言

require("global.func.php教程");
$fid=isset($_GET["id"])?intval($_GET["id"]):0;
$page=isset($_GET["page"])?intval($_GET["page"]):1;
if($_SERVER["REQUEST_METHOD"]=="POST")
{
 if(!file_exists("1.php"))
 {
  writeFile("1.php",$array=array());
 }
 $arr=require("1.php");
 $post=array();
 unset($_POST["Submit"]);
 foreach($_POST as $k=>$v)
 {
  $post[$k]=addslashes(htmlspecialchars($v));
 }
 $post["content"]=str_replace("n","
",$post["content"]);
 $post["id"]=count($arr)+1;
 $post["date"]=time();
 $post["fid"]=$fid;
 $post["ip"]=$_SERVER["REMOTE_ADDR"];
 $arr[]=$post;

 writeFile("1.php",$arr);
 
 echo "<script>location.href="index.php?page=$page"</script>";
 exit;
}
?>



发帖
<script><br />var arr=new Array();<p> function ckusername()<br /> {<br /> if(document.form1.username.value.length<3)<br /> {<br /> document.getElementById("user_msg").innerHTML="<font color="red"><b>用户名不能小于3个字符";<br /> arr[0]=1;<br /> }else<br /> {<br /> document.getElementById("user_msg").innerHTML="<font color="green"><b>&radic;";<br /> arr[0]=0;<br /> }<br /> <br /> <br /> }<br /> function ckcontent()<br /> {<br /> <br /> if(document.form1.content.value.length<8||document.form1.content.value.length>255)<br /> {<br /> document.getElementById("content_msg").innerHTML="<font color="red"><b>内容8-255个字符";<br /> arr[1]=1;<br /> }else<br /> {<br /> document.getElementById("content_msg").innerHTML="<font color="green"><b>&radic;";<br /> arr[1]=0;<br /> }<br /> }<br /> <br /> function c()<br /> {<br /> if(arr.length<2)<br /> {<br /> return false;<br /> }<br /> for(x in arr)<br /> {<br /> if(arr[x]==1)<br /> {<br /> return false;<br /> }<br /> }<br /> <br /> form1.submit();<br /> <br /> }<br /> <br /></script>



 
   
     
   
 
     
   
   
     
   
 
     
   
   
     
   
 
用户
     

     

     

       
     


ini_set("display_errors",0);
require("global.func.php");
?>

显示像163评论




PPC备用论坛(递归限制15层+主题)


echo " 发帖
";
if(file_exists("1.php"))
{
 $__array=require("1.php");
}
else
{
 $__array=array();
}
$page=isset($_GET["page"])?intval($_GET["page"]):1;
$pagesize=5;
$offset=($page-1)*$pagesize;
$__str="";
function getTotal()
{
 global $__array;
 $i=0;
 foreach($__array as $k=>$v)
 {
  if($v["fid"]==0)
  {
   $i=$i+1;
  }
 }
 return $i;
}
function getFid0()
{
 global $__array,$__str;
 
 foreach ($__array as $k=>$v)
 {
  if($v["fid"]==0)
  {
   $fid0[]=$v;
  }
  
 }
 return array_reverse($fid0);
}
$fid0=getFid0();
function show($fid0,$pagesize,$offset)
{
 global $__str,$page;
 foreach (array_slice($fid0,$offset,$pagesize,true) as $k=>$v)
 {
  
   $__str.="

";
   $__str.=$v["ip"]."用户:".$v["username"]."内容:".$v["content"]."回复";
   showChild($v["id"]);
   $__str.="

";
   
  
  
 }
}

function showChild($id,$i=0)
{
 global $__array,$__str,$page,$offset;
 
 
 if($i==15)//递归层数
 {
  return;
 }
 $i++;
 foreach($__array as $k=>$v)
 {
  if($v["fid"]==$id)
  {
   $__str.= "

";
   $__str.= $__array[$k]["ip"]."用户:".$__array[$k]["username"]."内容:".$__array[$k]["content"]."回复";
   showChild($v["id"],$i);
   $__str.= "

";
  }
 }
}

show($fid0,$pagesize,$offset);
$total=getTotal();

echo $__str;
pageft($total,$pagesize,"index.php");
echo "
".$pagenav;
?>

global.func.php文件代码如下

function writeFile($id,$array)
{
 $content="";
 return safe_file_put_contents($id,$content);
}
/**
*写入文件
*@param string $filename
*@param string $contents
*@return boolean
*/
function safe_file_put_contents($filename,&$contents)
{
 $fp=fopen($filename,"wb");
 if($fp)
 {
  flock($fp,LOCK_EX);
  fwrite($fp,$contents);
  flock($fp,LOCK_UN);
  fclose($fp);
  return true;
 }else
 {
  return false;
 }
}


/**
*读取文件
*@param string $filename
*@return $data|false
*/
function safe_file_get_contents($filename)
{
 $fp=fopen($filename,"rb");
 if($fp)
 {
  flock($fp,LOCK_SH);
  clearstatcache();
  $filesize=filesize($filename);
  if($filesize>0)
  {
   $data=fread($fp,$filesize);
  }else
  {
   $data=false;
  }
  flock($fp,LOCK_UN);
  fclose($fp);
  return $data;
 }else
 {
  return false;
 }
}
function pageft($total,$displaypg=10,$url=''){
global $page,$firstcount,$pagenav,$_SERVER;

$GLOBALS["displaypg"]=$displaypg;

if(!$page) $page=1;

if(!$url){ $url=$_SERVER["REQUEST_URI"];}

$parse_url=parse_url($url);
@$url_query=$parse_url["query"];
if($url_query){
$url_query=ereg_replace("(^|&)page=$page","",$url_query);

$url=str_replace($parse_url["query"],$url_query,$url);

if($url_query) $url.="&page"; else $url.="page";
}else {
$url.="?page";
}

$lastpg=ceil($total/$displaypg);
$page=min($lastpg,$page);
$prepg=$page-1;
$nextpg=($page==$lastpg ? 0 : $page+1);
if(!$page) $page=1;
$firstcount=($page-1)*$displaypg;


$pagenav.=" 首页 ";
if($prepg) $pagenav.=" 上页 "; else $pagenav.="上页 ";
if($nextpg) $pagenav.=" 下页 "; else $pagenav.="下页 ";
$pagenav.=" 尾页";

$pagenav.=" 到 页";
}
?>

//保存的1.php文件数数组形式,如下格式

  0 =>
  array (
    'username' => 'test',
    'content' => 'php100.com',
    'id' => 1,
    'date' => 1253853347,
    'fid' => 0,
    'ip' => '116.226.2.200',
  ),
  1 =>
  array (
    'username' => 'aaaaaaaaaaad',
    'content' => 'www.bkjia.com',
    'id' => 2,
    'date' => 1253857672,
    'fid' => 0,
    'ip' => '116.226.6.188',
  ),
 
)?>

 


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template