- Output for 5.5.24 - 5.5.30, 5.6.8 - 5.6.15
- Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /in/pGuuG on line 3
Process exited with code 255.
<?php
public function validateUPCA($value)
{
$upc = strval($value);
$stringLength = strlen($upc);
if($stringLength < 12 || $stringLength > 13 || intval($upc)==0)
{
return false;
}
$odd_sum = 0;
$even_sum = 0;
for($i = 0; $i < $stringLength - 1; $i++)
{
if($i % 2 === 1)
{
$even_sum += $upc[$i];
}
else
{
$odd_sum += $upc[$i];
}
}
if ($stringLength == 12)
{
// UPC-A format. Odd Sum * 3
$total_sum = $even_sum + $odd_sum * 3;
}
else
{
// EAN format. Even Sum * 3
$total_sum = $odd_sum + $even_sum * 3;
}
$modulo10 = $total_sum % 10;
$check_digit = $modulo10 == 0 ? 0 : 10 - $modulo10;
return $upc[$stringLength - 1] == $check_digit;
}
public main()
{
$value = 840018115309;
$res = validateUPCA($value);
echo "res: $res\n";
}