The function should look like this:
function EAN13CheckDigit($str){ $sum=0; $code=str_split($str); $sum=($code[1]+$code[3]+$code[5]+$code[7]+$code[9]+$code[11])*3; $sum+=$code[0]+$code[2]+$code[4]+$code[6]+$code[8]+$code[10];
$sum = ($sum % 10 == 0) ? 0 : (10-($sum %10));
return $sum; }
The problem was the case when sums MOD is 0 .. then the check digit is 10 but it should be 0.
Log in to post a comment.