public static function cpf($cpf)
    {
        // Extract numbers
        $cpf = preg_replace('/[^\d]/', '', $cpf);

        // Check amount of numbers
        if (strlen($cpf) > 11) {
            return false;
        }
        $cpf = str_pad($cpf, 11, '0', STR_PAD_LEFT);

        // Check for same digit sequence
        if (preg_match('/(\d)\1{10}/', $cpf)) {
            return false;
        }

        // Calculate check digits
        for ($t = 9; $t < 11; $t++) {
            for ($d = 0, $c = 0; $c < $t; $c++) {
                $d += $cpf{$c} * (($t + 1) - $c);
            }
            $d = ((10 * $d) % 11) % 10;
            if ($cpf{$c} != $d) {
                return false;
            }
        }

        return $cpf;
    }