我试图过滤一些日志,就像我需要它们,并试图使其动态。我有一些域名,我试图从中过滤一些东西,并且它们都像我想要的那样工作 - 但现在我更改了域名,现在我的代码不再工作了。它说一个变量没有被定义。为什么PHP告诉我这个变量没有定义?
$sp_bots = shell_exec("grep bot | awk '{print $12}' /var/www/laravel/logs/vhosts/zahnmedizinisches-fachzentrum-berlin.de.log");
$array_sp_bots = explode("\n", $sp_bots);
$all_bots = array();
foreach($array_sp_bots as $bots){
if(strpos($bots, "bot")){
$all_bots[] = $bots;
}
}
# count values of strings in array
if (!empty($all_bots)) {
$bots = array_count_values($all_bots);
arsort($bots);
$mostOccuring = max(array_count_values($all_bots));
$bot_keys = array_keys($bots);
#number of total bots
$count_bots = count($all_bots);
}
,并在我的回报:
return view('/domains/data', [
'count_bots' => $count_bots,
'bot_keys' => $bot_keys,
'mostOccuring' => $mostOccuring,
]);
但在我回报所有三个变量是不确定的..任何人都知道这是为什么?
什么的$更改域后sp_bots输出? – Sabari
定义$ all_bots,如$ all_bots = array();上面的foreach – Surace
因为你从来没有定义'$ all_bots',只是假设当你',它已经存在$ all_bots [] = $机器人;' –