3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseLog($log) { $lines = explode("\n", $log); $history = array(); foreach($lines as $key => $line) { if(strpos($line, 'commit') === 0 || $key + 1 == count($lines)){ if(!empty($commit)){ $commit['message'] = substr($commit['message'], 4); array_push($history, $commit); unset($commit); } $commit['hash'] = substr($line, strlen('commit') + 1); } else if(strpos($line, 'Author') === 0){ $commit['author'] = substr($line, strlen('Author:') + 1); } else if(strpos($line, 'Date') === 0){ $commit['date'] = substr($line, strlen('Date:') + 3); } elseif (strpos($line, 'Merge') === 0) { $commit['merge'] = substr($line, strlen('Merge:') + 1); $commit['merge'] = explode(' ', $commit['merge']); } else { if(isset($commit['message'])) { $commit['message'] .= $line; } else { $commit['message'] = $line; } } } return $history; } $gLog = <<< 'EOD' commit 56ed4ea370bd334580adb00d7c15f32e67b8164f (HEAD -> dev, origin/dev) Author: Alexander Jank <alex@zeraton.de> Date: Fri Feb 19 09:23:51 2021 +0100 chore(tools): configure eslint commit 6fa00559d5e9f1d71efe1382bfc21200fdb79fb1 Author: Alexander Jank <alex@zeraton.de> Date: Fri Feb 19 09:18:43 2021 +0100 feat(gql): add codegen commit d07218637cc7315d9b27e6a726a0eb43f336278b Author: Alexander Jank <alex@zeraton.de> Date: Wed Feb 17 12:11:43 2021 +0100 chore(git): remove files commit c12bb8e763cacc6ea2ef543462dc61d032c30ad4 Author: Alexander Jank <alex@zeraton.de> Date: Wed Feb 17 12:10:33 2021 +0100 feat(backend): add schemas commit 19a17d077c703ba5a1091272c1af1cb9a8e25865 Author: Alexander Jank <alex@zeraton.de> Date: Wed Feb 17 10:24:14 2021 +0100 feat(backend): add EOD; var_dump(parseLog($gLog));

preferences:
24.96 ms | 408 KiB | 5 Q