PHP Classes

File: helper/checkInn.php

Recommend this page to a friend!
  Classes of Alexey Starikov   PHP Helper Class   helper/checkInn.php   Download  
File: helper/checkInn.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Helper Class
Call helper functions that are loaded dynamically
Author: By
Last change:
Date: 5 years ago
Size: 1,092 bytes
 

Contents

Class file image Download
<?php

/**
 * ????????? ??? (????????????????? ????? ?????????????????) ?? ????????????
 */

return function ($n)
{
    if (!
is_scalar($n))
    {
       
//triggertrigger_error('Scalar type expected, ' . gettype($n) . ' given ', E_USER_WARNING);
       
return false;
    }
   
$n = strval($n);
    if (!
in_array(strlen($n), array(10, 12)) || ! ctype_digit($n))
    {
        return
false;
    }

    if (
strlen($n) == 10)
    {
       
$sum = 0;
        foreach (array(
2, 4, 10, 3, 5, 9, 4, 6, 8) as $i => $weight)
        {
           
$sum += $weight * substr($n, $i, 1);
        }
        return
$sum % 11 % 10 == substr($n, 9, 1);
    }

   
#??? 12 ??????:
   
$sum1 = $sum2 = 0;
    foreach (array(
7, 2, 4, 10, 3, 5, 9, 4, 6, 8) as $i => $weight)
    {
       
$sum1 += $weight * substr($n, $i, 1);
    }
    foreach (array(
3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8) as $i => $weight)
    {
       
$sum2 += $weight * substr($n, $i, 1);
    }
    return (
$sum1 % 11 % 10) . ($sum2 % 11 % 10) == substr($n, 10, 2);
};
?>