Skip to content

Instantly share code, notes, and snippets.

@tannerburson
Created June 26, 2009 23:18
Show Gist options
  • Select an option

  • Save tannerburson/136814 to your computer and use it in GitHub Desktop.

Select an option

Save tannerburson/136814 to your computer and use it in GitHub Desktop.
<?
//This is terribly insecure. We don't even pretend that we're authenticating here.
//We take parameters straight from _GET.
//Don't actually use this as is, please.
//Simple UPC -> ISBN code
function parseUPC($upc) {
if(false !== strstr($upc,'978')){
$isbn = substr($upc,3,9);
$xsum=0;
$add=0;
for ($i=0; $i< 9; $i++) {
$add = substr($isbn,$i,1);
$xsum += (10 - $i ) * $add;
}
$xsum = $xsum % 11;
$xsum = 11 - $xsum;
if ($xsum == 10) { $xsum = "X"; }
if ($xsum == 11) { $xsum = "0"; }
$isbn .= $xsum;
return $isbn;
}
else
return $upc;
}
if($_GET['isbn']) {
$fp = fopen('isbns.txt','a');
$isbn = parseUPC($_GET['isbn']);
$isbn .= "\r\n";
fwrite($fp, $isbn);
fclose($fp);
echo "added " . $isbn;
exit;
}
?>
Not Added
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment