$strings = file('data.dat');
foreach($strings as $string)
$array[] = split('|', $string);
now you have 2d-array $array, containing all the records in your data.dat .
Then sort it by time descending (using usort(), or maybe there is some easier way) and use first four items.]
Sure this method costs loads of memory, if your file is big enough.
Another way is like this
foreach ($strings as $string)
{
$tmp = 0;
foreach($array as $record)
if ($string[2] < $record[2]) $tmp = 1; //boolean var to check if $string is older than all the records in $array
if (!tmp or (count($array) < 4))
{// here to be some code that replace oldest record in $array with $string.
// you can try to write it yourself :)
}
}
Here we never keep $array longer than 4 records, but the code becomes more complicated.