3v4l.org

run code in 500+ PHP versions simultaneously
<?php $inputs = [ '44d', '5h 53s', '1d 3h 16m 2s', '2d 57m', '3m', '2m 22s', '6d 6s' ]; foreach ($inputs as $input) { preg_match('/^(?:(\d+)d ?)?(?:(\d+)h ?)?(?:(\d+)m ?)?(?:(\d+)s)?$/', $input, $m); echo "$input = " . ((int) ($m[1] ?? 0) * 86400) + ((int) ($m[2] ?? 0) * 3600) + ((int) ($m[3] ?? 0) * 60) + (int) ($m[4] ?? 0) . " seconds\n"; }

preferences:
47.62 ms | 1138 KiB | 5 Q