<?php set_time_limit(0); /*处理日志文件内容中包含array(开头,)结尾的内容到数据库,设置超时及缓存可处理100Mb以内文件 insert调用外部的php 测试数据array(列名=>内容) */ $file_path = "2019-08-28.log"; echo $file1[$i1]."<br>"; if(file_exists($file_path)){ $file_arr = file($file_path); $RowN=0 ;//行 for($i=0;$i<count($file_arr);$i++){//逐行读取文件内容 $n= strpos($file_arr[$i],"array (");//数组开头 $n1=strpos($file_arr[$i],")");//数据结尾 if ($n>0){ $Du=1; continue;//跳出,不记录array( } elseif($file_arr[$i].(1)>")") { $Du=0; continue;//跳出,不记录) } //echo "<pre>"; if ($Du==1 ){ if (strlen($file_arr[$i])> 8){ #去无效内容 $b=str_replace(" ","",$file_arr[$i]); $b=str_replace(",","",$b); $b=str_replace("\n","",$b); $b=str_replace("'","",$b); #分组内容到数组 $a=explode("=>",$b); $temp[$a[0]]=$a[1]; $t++; if ($a[0]== "update_time"){ if (count($temp)==31){ //insert($link,"debuglog",$temp); unset($temp); } else { echo "<pre>"; var_dump( $temp); unset($temp); } } } } } } ?>
第一篇php处理log 数组,自用
最新推荐文章于 2020-09-28 19:11:41 发布