As our clients products did not have UPC codes we put together this little function based on UPC-A description on wikipedia.
function UPC() {
$odd_sum = $even_sum = 0;
for ($i = 1; $i < 12; $i++) {
$digits[$i] = rand(0,9);
if($i % 2 == 0)
$even_sum += $digits[$i];
else
$odd_sum += $digits[$i];
}
$digits[$i] = 10 - ((3 * $odd_sum + $even_sum) % 10);
return implode('',$digits);
}
echo UPC();
Check this website to validate PHP generated UPC code
3 comments:
Thank you so much =) I used this function for www.discountmee.com! I will donate a generous amount to everyone who has helped make this dream become a reality.
It doesn't work when i try to scan the barcode
Yes its really does work...it becomes a reality...thanks..
Buy UPC codes
Post a Comment