//$str = 'Иванов Иван Иванович 01.01.1970 353';
$str = 'Иванов Иван 01.01.1970 353';
extract( splitLineBySpace($str) );
var_dump($lastname, $firstname, $secondname, $birthdate, $number);
function splitLineBySpace(string $str): array
{
$lastname = $firstname = $secondname = $birthdate = $number = '';
$patt = '~(\S+)\h(\S+)(?:\h(\S+))?\h((?:\d\d\.){2}\d{4})\h(\d+)~';
if (preg_match($patt, $str, $arr)) {
if (count($arr) == 6) {
[, $lastname, $firstname, $secondname, $birthdate, $number] = $arr;
} else {
[, $lastname, $firstname, $birthdate, $number] = $arr;
}
}
return compact('lastname', 'firstname', 'secondname', 'birthdate', 'number');
}