如何从文本的最后一行开始读取?

解决方案 »

  1.   


    if(!file_exists("tx.txt"))return ;
    $file=file("tx.txt");
    echo "<pre>";
    var_dump($file);
    foreach($file as $value)
    {
    $foo=array_pop($file);//将最后一个元素弹出栈。
    var_dump($foo);
    }
    echo "</pre>";
      

  2.   

    <?php
    echo '<pre>';
     function gettime(){
         $nowtime = explode(' ',microtime());
         return $nowtime[0]+$nowtime[1];
     }
    $start = gettime();
    $data=file_get_contents('query.log');$dataarray=explode('[idxmain]',$data);
    $str='';
    foreach($dataarray as $key=>$val){

    if($key==0){
    $str.=substr($val,strpos($val,'[')+1,28).','; }elseif($key>=1){
    $str.=substr($val,0,strpos($val,'[')).',';

    $str.=substr($val,strpos($val,'[')+1,28).',';

    }
    }
    $keyword='';
    $array=explode(',',$str);
    $i=0;
    $j=0;
    foreach($array as $key=>$val){
    if($val!=''){
    $keyword.=trim($val);
    if($j==$i){
    $keyword.=',';
    }

    $j++;
    }
    $i++;
    }
    $wordarray=explode(',',$keyword);
    $new_array =array_count_values($wordarray);
    print_r($new_array);
    echo '</pre>';echo '<br />';
     $end  = gettime();
     $count =$end-$start;
     echo ' 用时:'.$count;
    ?>