$a = "1d 35m";
$a = '1d 35m';
if (preg_match('/^(?:(?<days>\d+)d)?\s*(?:(?<hours>\d+)h)?\s*(?:(?<minutes>\d+)m)?\s*(?:(?<seconds>\d+)s)?$/', $a, $matches)) {
$resultSec = intval($matches['days'] ?? '') * 86400 + intval($matches['hours'] ?? '') * 3600
+ intval($matches['minutes'] ?? '') * 60 + intval($matches['seconds'] ?? '');
echo $resultSec;
} else {
echo 'error';
}
// 88500