保存信息到文件里
<?php
$time = date('Y-m',time());
if(!is_dir($time))
{
    mkdir($time,0700);
}
$nick = '彩霞飞飞';
$str = '今天天气好好啊!';
$path = $time.'/'.$time.'.txt';
$t = date('Y-m-d h:i:s',time());
//$msg = "$nick ".$t.'
// '.$str.'
// ';
$msg .= "\r\n";  //保存记录到文本中   实现换行
$t = array();
$t['u_nick'] = $nick;
$t['time'] = $tim;
$t['cont'] = $str;
$msg = json_encode($t);
$msg .= '
';
file_put_contents($path,$msg,FILE_APPEND);//在文件末尾追家
?>

分页读取固定条数的信息

<?php
$time = date('Y-m-d',time());
$path = $time.'/'.$time.'.txt';
$perpage = 2;
$currentPage = 3;
$total = count(file($path));
$totalPage = 1;
$totalPage = ceil($total / 2);
$start = ($currentPage - 1)*$perpage;
$end = $currentPage * $perpage;
if($total < $perPage || $currentPage == $totalPage)
{
    $end = $total;
}
if(file_exists($path))
{
    $file = file($path);
    $file = array_reverse($file); // 数组倒序
    $cont = array();
    for($i = $end-1;$i >= $start;$i--)
    {
        $cont[] = json_decode($file[$i]);
        var_dump($cont);
    }
    $t = array();
    $t['k'] = 'chatrecord';
    $t['totalPage'] = $totalPage;
    $t['currentPage'] = $currentPage;
    $t['content'] = $cont;
    $ms = json_encode($t);
    var_dump($ms);exit;
}
?>
经过自己测试fgets()方法读取只能从第一行按顺序一行一行的读取,如果做分页,他就不行,无论怎样循环,都是从第一行开始往后读的,所以不能用