gpt4 book ai didi

PHP explode : script working on Windows, 不在 Debian 上

转载 作者:可可西里 更新时间:2023-11-01 10:34:53 24 4
gpt4 key购买 nike

我有一个脚本可以在 Windows 上完美运行,但不能在 Debian 上运行。两者都运行相同的 PHP 版本,我似乎无法弄清楚为什么它不能在 Debian 上运行。

$content = file_get_contents('ua.log');
$arr = explode(PHP_EOL, $content);

foreach($arr as $x) {
$i = explode(' ', $x);
if($i[11] == '"user/agent1.0"'){
$ips[] = $i[0];
}
else{
};
};

我检查了权限并使用了长目录 (/var/www/ua.log)。似乎仍然没有工作,因为 $i 返回 NULL。

最佳答案

您可能会发现它更易于使用

foreach (file("/some/file.txt", FILE_IGNORE_NEW_LINES) as $x) {
....
}

关于 $i = explode(' ', $x); - 它可能也有点不同。最好使用类似 preg_split(",\s+,", $x); 之类的东西,但这取决于确切的文件内容。

谢谢。

关于PHP explode : script working on Windows, 不在 Debian 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32818569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com