Edmonds Commerce Logo
  • home
    • blog
  • ecommerce
    • product catalogue
    • order processing
    • customer services
    • stock control
    • human resources
    • management information
  • development
    • oscommerce
    • php
    • mysql
    • open source
    • performance tuning
  • design
  • marketing
  • contact us
    • pricing

Edmonds Commerce Blog

Freelance PHP Ecommerce and SEO Developer in the UK

Latest Posts

Git Ignore All Files Except PHP etc + Solution
PHP 5.3 Is Released
Netbeans 6.7 is Out. Yay :-)
RGBA Cross Browser Support + Solution

Most Popular Posts

Magento Developer UK Freelance osCommerce UK Magento UK Developers on Linked.in CRE Loaded UK

EAN13 Barcode Check Digit with PHP

February 15th, 2008
Read More barcode, php

EAN13 is a barcode format. It consists of 12 numbers which you will generally have a range assigned to you. The 13th digit is called the check digit and is formulated by loooking at the other 12 digits. The purpose of the check digit is to ensure that the number is being read correctly as if any of the numbers do not match up, the check digit will not validate.

If you need to create check digits in PHP, here is my handy function:

PLAIN TEXT
PHP:
  1. function ean13_check_digit($digits){
  2. //first change digits to a string so that we can access individual numbers
  3. $digits =(string)$digits;
  4. // 1. Add the values of the digits in the even-numbered positions: 2, 4, 6, etc.
  5. $even_sum = $digits{1} + $digits{3} + $digits{5} + $digits{7} + $digits{9} + $digits{11};
  6. // 2. Multiply this result by 3.
  7. $even_sum_three = $even_sum * 3;
  8. // 3. Add the values of the digits in the odd-numbered positions: 1, 3, 5, etc.
  9. $odd_sum = $digits{0} + $digits{2} + $digits{4} + $digits{6} + $digits{8} + $digits{10};
  10. // 4. Sum the results of steps 2 and 3.
  11. $total_sum = $even_sum_three + $odd_sum;
  12. // 5. The check character is the smallest number which, when added to the result in step 4,  produces a multiple of 10.
  13. $next_ten = (ceil($total_sum/10))*10;
  14. $check_digit = $next_ten - $total_sum;
  15. return $digits . $check_digit;
  16. }

Other Barcode Related Resources:

http://phpclasses.fonant.com/browse/package/3643.html

http://thinkabdul.com/2007/01/04/barcoder-freeware-ean-13-barcode-reader-for-java-j2me-mobiles/

Possibly Relevant Posts:

  • Setting up a 64bit Linux PHP Development Enviroment
  • phpuk2009 Tomorrow
  • Flash Messenger Bug in Zend Framework + Patch
  • PHP Execution After Client Disconnection
  • Check if MySQL Table Exists

Feed | Respond | Trackback

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • business
    • creloaded
    • css
    • curl
    • customer services
    • debugging
    • eclipse
    • ecommerce
    • edmondscommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • git
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • mac
    • magento
    • management
    • misc
    • mod_rewrite
    • mysql
    • open suse
    • oscommerce
    • php
    • plesk
    • portfolio
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • ria
    • scraping
    • search engine optimisation
    • security
    • seo
    • spidering
    • twitter
    • ubuntu
    • Uncategorized
    • usability
    • vps
    • web design
    • web development
    • Windows
    • xampp
    • zend framework
    • zip
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    alpha browser case creloaded css curl development directories filezilla firefox flush google googlecheckout hosts file html internet explorer jaunty links linux magento migration mod_security mysql myths oscommerce php plesk reciprocal linking rgba search engine optimisation seo spidering spotify ssl synchronisation table transparency ubuntu uk virtualbox web web design xml zend form zend framework
  • Random Posts

    • Optimised Magento AMI for Amazon EC2 - Host Magento on the Cloud
    • Plesk phpMyAdmin Copy Database Bug + Workaround
    • Securing a LAMP Server with mod_security
    • Magento Tip - Rename Your Theme Directory
    • Use Grep To Find Text In Folders
    • Online Business Tools
    • Magento Bulk Cache / Index Update Script
    • Magento More Detailed Exception Log
    • PHPNW08 - PHP Conference Up North!!
    • Twitter Bar Firefox Addon
  • Most Popular Posts

    • MySQL Copy Table from One Database to Another (15)
    • PHP Email Attachment Function (10)
    • PHP Save Images Using cURL (6)
    • PHP, cURL, CURLOPT FOLLOWLOCATION and open basedir Or Safe Mode (6)
    • Magento Sites Go Down if Magentocommerce.com Goes Down (6)
  • Recent Comments

    • admin on Migrate Magento to Alternative Server
    • jon on Migrate Magento to Alternative Server
    • admin on Magento Sites Go Down if Magentocommerce.com Goes Down
    • Sam on Magento Sites Go Down if Magentocommerce.com Goes Down
    • Email Attachments with PHP | S-Carter.co.uk on PHP Email Attachment Function

Edmonds Commerce related questions? Send us a message or call us on 0844 357 0201.

Freelance PHP Web Design UK Commercial Web Design