- preg_replace_callback: documentation ( source)
- preg_match: documentation ( source)
<?php
function convertToSeconds($time) {
if (!preg_match('/(\d{1,2}):(\d{2})/', $time)) {
return 0;
}
return preg_replace_callback('/(\d{1,2}):(\d{2})/', function($e) {
return $e[1] * 60 + $e[2];
}, $time);
}
echo convertToSeconds('02:22');