Generating Barcode Using PHP

As the world is digitalising developers face problems regarding developing sites with newer technologies and advancements for the user interaction.

Every site provides various features for payments and user recognization. Today we will take Generating Barcode Using PHP  as our topic for our fellow developers.
A barcode is an optical, machine-readable, representation of data, the data usually describes something about the object that carries the barcode.We will use PHP to generate Barcode in this tutorial.
So, lets start with a new hurdle,

In this script, we are using coding which will generate barcodes in barcode format Code 128.
First, we will create index.php which will ask for the user input for which Barcode has to be created

PHP Barcode Generator

Detail Informations
Enter Your Code

Now we will create createbarcode.php which will call function from Barcode code128 class for creating barcode
include(‘barcode128.php’); // include php barcode 128 class
// design our barcode display
echo ‘

echo bar128(stripslashes($_POST[‘barcode’]));
echo ‘

Now we have to create barcode128.php which is the class for generating barcode and is going to included by createbarcode.php

global $char128asc,$char128charWidth;
$char128asc=’ !”#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~’;
$char128wid = array(
‘212222’,’222122′,’222221′,’121223′,’121322′,’131222′,’122213′,’122312′,’132212′,’221213′, // 0-9
‘221312’,’231212′,’112232′,’122132′,’122231′,’113222′,’123122′,’123221′,’223211′,’221132′, // 10-19
‘221231’,’213212′,’223112′,’312131′,’311222′,’321122′,’321221′,’312212′,’322112′,’322211′, // 20-29
‘212123’,’212321′,’232121′,’111323′,’131123′,’131321′,’112313′,’132113′,’132311′,’211313′, // 30-39
‘231113’,’231311′,’112133′,’112331′,’132131′,’113123′,’113321′,’133121′,’313121′,’211331′, // 40-49
‘231131’,’213113′,’213311′,’213131′,’311123′,’311321′,’331121′,’312113′,’312311′,’332111′, // 50-59
‘314111’,’221411′,’431111′,’111224′,’111422′,’121124′,’121421′,’141122′,’141221′,’112214′, // 60-69
‘112412’,’122114′,’122411′,’142112′,’142211′,’241211′,’221114′,’413111′,’241112′,’134111′, // 70-79
‘111242’,’121142′,’121241′,’114212′,’124112′,’124211′,’411212′,’421112′,’421211′,’212141′, // 80-89
‘214121’,’412121′,’111143′,’111341′,’131141′,’114113′,’114311′,’411113′,’411311′,’113141′, // 90-99
‘114131’,’311141′,’411131′,’211412′,’211214′,’211232′,’23311120′ ); // 100-106

////Define Function
function bar128($text) { // Part 1, make list of widths
global $char128asc,$char128wid;
$w = $char128wid[$sum = 104]; // START symbol
for($x=0;$x<strlen($text);$x++) // GO THRU TEXT GET LETTERS
if (!( ($pos = strpos($char128asc,$text[$x])) === false )){ // SKIP NOT FOUND CHARS
$w.= $char128wid[$pos];
$sum += $onChar++ * $pos;
$w.= $char128wid[ $sum % 103 ].$char128wid[106]; //Check Code, then END
//Part 2, Write rows

“; for($x=0;$x<strlen($w);$x+=2) // code 128 widths: black border, then white space $html .= ”

return “$html



You can Download the whole Code Here Download Here

This is all what we have to do for generating Barcodes using PHP.

We hope this will help our young develpoers to expand and face the hurdles
So,guys learn more work harder
Hurdles aren’t really hurdles


  1. Nice weblog right here! Also your web site rather a lot up very fast!
    What web host are you the use of? Can I get your affiliate link for your host?
    I wish my site loaded up as quickly as yours

    May 19, 2017
    • Deepak Shah said:

      thanks for the appreciation means a lot to us

      May 21, 2017
  2. Raman said:

    The tutorial is very handy. Very useful. Thanks.

    June 9, 2017
    • Saurabh Dubey said:

      Thanks Raman, for the appreciation.


      June 10, 2017
  3. pranav sonde said:

    thank you so much its very useful code thank you so much again…….

    June 23, 2017

Leave a Reply

Your email address will not be published. Required fields are marked *