<?php

$rc = filter_input(INPUT_GET, 'rc', FILTER_SANITIZE_NUMBER_INT);

$valid = false;

if ($rc !== null && $rc !== false) {
    $rc = str_replace('-', '', $rc);
    $len = strlen($rc);

    if ($len === 9 || $len === 10) {
        $rr = (int)substr($rc, 0, 2);
        $mm = (int)substr($rc, 2, 2);
        $dd = (int)substr($rc, 4, 2);

        if ($mm > 50) $mm -= 50;
        if ($mm > 20) $mm -= 20;

        $year = ($rr >= 54 ? 1900 : 2000) + $rr;

        if ($mm >= 1 && $mm <= 12) {
            $days = cal_days_in_month(CAL_GREGORIAN, $mm, $year);
            if ($dd >= 1 && $dd <= $days) {
                if ($len === 9 || (int)$rc % 11 === 0) {
                    $valid = true;
                }
            }
        }
    }
}
?>
<!DOCTYPE html>
<html>
<head><title>rodne ci</title></head>
<body>
    <form method="get">
        <input type="text" name="rc" value="<?= htmlspecialchars($_GET['rc'] ?? '') ?>">
        <button type="submit">overit</button>
    </form>
    <?php if ($rc !== null && $rc !== false): ?>
        <p><?= $valid ? 'platne' : 'neplatne' ?></p>
    <?php endif; ?>
</body>
</html>