Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $fileFormatSample = '02.08.2012 83.7
- 04.08.2012 82.9
- 09.08.2012 82.1
- 26.08.2012 81.5
- 03.08.2012 83.0
- 10.08.2012 81.0
- 13.08.2012 83.7
- 22.08.2012 83.4
- 05.08.2012 82.2
- 25.08.2012 82.4
- 23.08.2012 82.5
- 31.08.2012 81.4';
- function sortFile($file)
- {
- $content = file_get_contents($file);
- $lines = preg_split("/[\r\n]+/", $content);
- $data = [];
- foreach ($lines as $line) {
- $line = explode(' ', $line);
- $ts = DateTime::createFromFormat('d.m.Y', $line[0])->getTimestamp();
- $data[$ts] = $line[1];
- }
- ksort($data);
- $finalData = [];
- foreach ($data as $time => $weight) {
- $finalData[Date('d.m.Y', $time)] = $weight;
- }
- file_put_contents($file, implode("\n", $finalData));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement