当前位置:网站首页>Use PHP to count command line calls on your computer

Use PHP to count command line calls on your computer

2022-06-13 03:14:00 wks19891215

<?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);
 ?>

In the development machine mac Upper test passed ~ And in the virtual machine centos Failed on , Because on the virtual machine php Safe mode is not turned off .

PS: Regular expressions are so powerful !


原网站

版权声明
本文为[wks19891215]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280532253837.html