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

CRELoaded Remove Google Ads -
ICECat Integration with osCommerce, Magento etc
Magento UK
PHP Cached Download Function

Most Popular Posts

PHP Email Attachment Function Freelance osCommerce UK Ultimate osCommerce Checkout - Fast and Friendly PHP : Dead Easy Excel Export

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/

Bookmark this Post
Add 'EAN13 Barcode Check Digit with PHP' to Del.icio.usAdd 'EAN13 Barcode Check Digit with PHP' to diggAdd 'EAN13 Barcode Check Digit with PHP' to FURLAdd 'EAN13 Barcode Check Digit with PHP' to blinklistAdd 'EAN13 Barcode Check Digit with PHP' to redditAdd 'EAN13 Barcode Check Digit with PHP' to Feed Me LinksAdd 'EAN13 Barcode Check Digit with PHP' to TechnoratiAdd 'EAN13 Barcode Check Digit with PHP' to Yahoo My WebAdd 'EAN13 Barcode Check Digit with PHP' to NewsvineAdd 'EAN13 Barcode Check Digit with PHP' to SocializerAdd 'EAN13 Barcode Check Digit with PHP' to Ma.gnoliaAdd 'EAN13 Barcode Check Digit with PHP' to Stumble UponAdd 'EAN13 Barcode Check Digit with PHP' to Google BookmarksAdd 'EAN13 Barcode Check Digit with PHP' to RawSugarAdd 'EAN13 Barcode Check Digit with PHP' to SquidooAdd 'EAN13 Barcode Check Digit with PHP' to SpurlAdd 'EAN13 Barcode Check Digit with PHP' to BlinkBitsAdd 'EAN13 Barcode Check Digit with PHP' to NetvouzAdd 'EAN13 Barcode Check Digit with PHP' to RojoAdd 'EAN13 Barcode Check Digit with PHP' to BlogmarksAdd 'EAN13 Barcode Check Digit with PHP' to ShadowsAdd 'EAN13 Barcode Check Digit with PHP' to Co.mments
Add 'EAN13 Barcode Check Digit with PHP' to ScuttleAdd 'EAN13 Barcode Check Digit with PHP' to BloglinesAdd 'EAN13 Barcode Check Digit with PHP' to TailrankAdd 'EAN13 Barcode Check Digit with PHP' to SegnaloAdd 'EAN13 Barcode Check Digit with PHP' to OKnotizieAdd 'EAN13 Barcode Check Digit with PHP' to NetscapeAdd 'EAN13 Barcode Check Digit with PHP' to Bookmark.itAdd 'EAN13 Barcode Check Digit with PHP' to AskAdd 'EAN13 Barcode Check Digit with PHP' to SmarkingAdd 'EAN13 Barcode Check Digit with PHP' to LinkagogoAdd 'EAN13 Barcode Check Digit with PHP' to DeliriousAdd 'EAN13 Barcode Check Digit with PHP' to SocialdustAdd 'EAN13 Barcode Check Digit with PHP' to Live-MSNAdd 'EAN13 Barcode Check Digit with PHP' to SlashDotAdd 'EAN13 Barcode Check Digit with PHP' to SphinnAdd 'EAN13 Barcode Check Digit with PHP' to DiggitaAdd 'EAN13 Barcode Check Digit with PHP' to SeotribuAdd 'EAN13 Barcode Check Digit with PHP' to FaceBookAdd 'EAN13 Barcode Check Digit with PHP' to UpnewsAdd 'EAN13 Barcode Check Digit with PHP' to WikioAdd 'EAN13 Barcode Check Digit with PHP' to Social Bookmarking Reloaded

Feed | Respond | Trackback

Leave a Reply

  • RSS Feed
  • Categories

    • apache
    • barcode
    • creloaded
    • curl
    • customer services
    • debugging
    • ecommerce
    • email
    • excel
    • firefox
    • flash
    • gd
    • graphs
    • hosting
    • icecat
    • internet news
    • javascript
    • link building
    • linux
    • magento
    • management
    • mod_rewrite
    • mysql
    • oscommerce
    • php
    • plesk
    • product catalogue
    • product feed
    • programming
    • regular expressions
    • scraping
    • search engine optimisation
    • spidering
    • ubuntu
    • web design
    • web development
    • Windows
    • xampp
    • zip
  • Archives

    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
  • Tags

    addons advanced adverts blackhat blocking css curl development directories find firefox google hosts file html javascript keywords links msn mysql myths operators oscommerce paid links paid placement performance php ppc reciprocal linking replace screen scraping security seo serp speed spider spidering tuning user friendly vista web web design web developer
  • Random Posts

    • Developing Web Applications in Windows
    • MySQL Add Column if Not Exists - PHP Function
    • MySQL DB Admin GUI for Windows / XAMPP
    • File Comparison on Ubuntu
    • MySQL Find and Replace
    • Advanced PHP Debug Function
    • PHP: Recursive Create Path (if not exists)
    • Speeding Up osCommerce
    • Debugging PHP Scripts
    • Product Feed Integration and Scraping Products from Supplier Web Sites

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

Freelance PHP Web Design UK Commercial Web Design