PHP Classes

File: helper/ean13Sum.php

Recommend this page to a friend!
  Classes of Alexey Starikov  >  PHP Helper Class  >  helper/ean13Sum.php  >  Download  
File: helper/ean13Sum.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: 3 years ago
Size: 402 bytes
 

Contents

Class file image Download
<?php
// ean13Sum ean8
return function($code, $type='ean13'){
   
$len = $type == 'ean13' ? 12 : 7;
   
$code = substr($code, 0, $len);
    if (!
preg_match('`[0-9]{'.$len.'}`', $code)) return('');
   
$sum = 0;
   
$odd = true;
    for(
$i=$len-1; $i>-1; $i--){
       
$sum += ($odd ? 3 : 1) * intval($code[$i]);
       
$odd = ! $odd;
    }
    return(
$code . ( (string) ((10 - $sum % 10) % 10)));
}
?>

For more information send a message to info at phpclasses dot org.