<?php
exec("cat ~/.zsh_history",$data);
exec("cat ~/.bash_history",$data);
foreach ($data as $str)
{
$str = preg_replace('/[0-9]|:|;/', "", $str);
$str=trim($str);
$pattern ='/^[a-z]+/';
preg_match($pattern,$str,$match);
$tmp = array_shift($match);
if($tmp!==NULL)
{
$buff[] = $tmp;
}
}
$buff = array_count_values($buff);
asort($buff);
var_dump($buff);
?>
在开发机mac上测试通过~而虚拟机中的centos上未通过,因为虚拟机上的php未关闭安全模式。
PS:正则表达式真强大!