我有一个名为“test.txt”的文件,其中包含以下内容:
BEGIN_GENERAL 8
LastLine 20130801000028 136606 57288915 25883895742573
FirstTime 20130701130426
LastTime 20130731235941
LastUpdate 20130802015823 1 0 0 0 0
TotalVisits 360
TotalUnique 246
MonthHostsKnown 0
MonthHostsUnknown 454
END_GENERAL
我希望通过将其更改为PHP中的日期来提取"LastUpdate"
和"20130802015823 1 0 0 0 0"
的函数。
所以我试过这个:
preg_match("/BEGIN_GENERAL(.*)END_GENERAL/is", $test, $matches);
$text= $matches;
答案 0 :(得分:1)
您可以在PHP中使用正则表达式来执行此操作。
<?php
$data = file_get_contents('test.txt');
preg_match('/^LastUpdate ([0-9]{14}) /ms', $data, $matches);
$last_update_date = date("Y-m-d H:i:s", strtotime($matches[1]));
print $last_update_date;