<?php
function is_ean13($ean13)
{
if (strlen($ean13) != 13) return 1; // le code-barres doit contenir 13 caractères
if (!is_numeric($ean13)) return 2; // le code-barres ne doit contenir que des chiffres
// on prend chaque chiffre un par un
// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
// on triple sa valeur
// on ajoute cette valeur à la somme totale
for ($index = 0; $index < 12; $index ++)
{
$number = (int) $ean13[$index];
if (($index % 2) != 0) $number *= 3;
$sum += $number;
}
$key = $ean13[12]; // clé de contrôle égale au dernier chiffre
// la clé de contrôle doit être égale à : 10 - (reste de la division de la somme des 12 premiers chiffres)
if (10 - ($sum % 10) != $key) return 3; else return 0;
}
echo is_ean13(7330510000000);
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Undefined variable $sum in /in/hf4PM on line 17
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 15
Warning: Trying to access array offset on int in /in/hf4PM on line 20
3
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Undefined variable $sum in /in/hf4PM on line 17
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 15
Warning: Trying to access array offset on value of type int in /in/hf4PM on line 20
3
Output for 7.4.0 - 7.4.33
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Undefined variable: sum in /in/hf4PM on line 17
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 15
Notice: Trying to access array offset on value of type int in /in/hf4PM on line 20
3