1 回答
TA贡献1807条经验 获得超9个赞
<?php
function getDateFromFile($file = 'text.txt')
{
$f = fopen($file, 'r');
$cursor = -1;
$line = '';
fseek($f, $cursor, SEEK_END);
$char = fgetc($f);
/**
* Trim trailing newline chars of the file
*/
while ($char === "\n" || $char === "\r") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
/**
* Read until the start of file or first newline char
*/
while ($char !== false && $char !== "\n" && $char !== "\r") {
/**
* Prepend the new char
*/
$line = $char . $line;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
$value = explode(";", $line);
$year = substr($value[1], 0, 4);
$month = substr($value[1], 4, 2);
$day = substr($value[1], 6, 2);
$hour = substr($value[1], 8, 2);
$min = substr($value[1], 10, 2);
$date = new DateTime("$year-$month-$day $hour:$min");`
return $date;
}
print_r(getDateFromFile("produkt_zehn_now_tu_20191225_20191226_05371.txt"));
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报