1 回答
TA贡献1862条经验 获得超6个赞
将$array包含所有用空格分隔的单词。
[
"0",
"5",
"*",
"*",
"1",
"tar",
"-zcf",
"var/backups/home.tgz",
"home\n0",
"5",
"*",
"*",
"1",
...
]
您需要拆分行并循环遍历它们。
对于第二个问题;用于array_slice
从数组中获取剩余的项目,然后将它们与implode
.
$jobs = "
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
";
$lines = explode("\n", trim($jobs));
foreach ($lines as $line) {
$array = explode(" ", $line);
$job = new Job;
$job->min = $array[0];
$job->hour = $array[1];
$job->day_month = $array[2];
$job->mes = $array[3];
$job->day_week = $array[4];
$job->command = implode(" ", array_slice($array, 5));
$job->save();
}
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报