Validate EAN13 Barcodes

function  validateEan13($digits){
	if (strlen($digits) == 12 ) {
		$even = $digits[1] + $digits[3] + $digits[5] + $digits[7] + $digits[9] + $digits[11];
		$even = $even * 3;
		$odd = $digits[0] + $digits[2] + $digits[4] + $digits[6] + $digits[8] + $digits[10];
		$total = $even + $odd;
	    
		$checksum = $total % 10;
		if($checksum != 0){$checksum = 10 - $checksum;} //930060717912+5, 501054800186+0
		return $digits.$checksum;
	}	 
	else{return 'error '.strlen($digits);}
}
validateEan13('930060717912') = 930060717912+5
validateEan13('501054800186') = 501054800186+0
validateEan13('503450493577') = 503450493577+8