Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Artur Graniszewski  >  PESEL validator  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example class
Class: PESEL validator
Validate Polish PESEL numbers
Author: By
Last change: Changed sourcecode formatting
Date: 2011-03-11 07:24
Size: 969 bytes
 

Contents

Class file image Download
<html>
<head>
    <title>Example</title>
    <style type="text/css">
    body {font-family: tahoma, verdana, arial; font-size: 12px;}
    </style>
</head>

<?php

$pesels 
= array(
    
'02070803628'// valid PESEL number
    
'02170803628'// invalid PESEL number
    
'07020803628'// valid PESEL number (checksum is the same as in first example, see PESEL checksum bug on wikipedia)
);

require_once(
'pesel.php');

foreach(
$pesels as $peselNumber) {
    try {
        
$pesel = new Pesel($peselNumber);
        
printf('<strong>PESEL #'.$peselNumber.
        
' is valid.</strong><br /><br />day of birth: <strong>%s-%s-%s</strong><br />sex: <strong>%s</strong>',
        
$pesel->getDayOfBirth(), $pesel->getMonthOfBirth(), $pesel->getYearOfBirth(), ($pesel->isMale() ? 'male' 'female'));
    } catch (
Exception $e) {
        echo 
'<strong>PESEL #'.htmlspecialchars($peselNumber).' is invalid</strong><br /><br />reason: <strong>'.$e->getMessage().'</strong>'
    }
    echo 
"<hr />";
}
?>

</html>