<?php header("Content-type:text/html;CharSet=utf-8"); $file = fopen("sqlstr.txt", "r"); $sql_arr=array(); $i=0; //输出文本中所有的行,直到文件结束为止。 while(! feof($file)) { $sql_arr[$i]= fgets($file);//fgets()函数从文件指针中读取一行 $i++; } fclose($file); $sql_arr=array_filter($sql_arr); //此处用变量$bianliang1来标识第一个数组 $bianliang1=‘aaa‘; foreach ($sql_arr as $k => &$v) { $newarr[$k] = explode($bianliang1, $v); } //此处用变量$bianliang1来标识第二个数组 $bianliang2=‘bbb‘; foreach ($newarr as $k => &$v) { if(!empty($v[1])){ $newtwo[$k] = explode($bianliang2, $v[1]); } } foreach ($newtwo as $k => &$v) { $aaa[] = $v[0]; } $i = count($aaa); $ok = array_count_values ($aaa); arsort($ok); echo ‘<pre>‘; echo "共".$i."条"; echo ‘<br>‘; print_r($ok); ?>
php日志分析小脚本,分析出每行包含相同字符串的统计数量(从大到小进行排序)
原文地址:http://itafei.blog.51cto.com/10862892/1970274