Q:

How to generate QR Code in PHP

belongs to collection: PHP Programming Exercises

0

How to generate QR Code in PHP

In this exercise, you will learn how to generate a QR Code in PHP in the easiest way.

QR Code stands for Quick Response code. Initially, it is developed for the automotive industry, but later it is widely used in a wider range of applications. By using this, we can replace a large amount of information, smart card data, consumer advertising, website url, telephone number, article and much more into a just two-dimensional matrix Barcode. It is capable of storing up to 4,296 alphanumeric characters of arbitrary text. The generated code can be read by a QR Code reader software using optical smart devices. PHP provides several libraries to generate QR code. Generating QR Code is very easy in PHP.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Generating QR Code using phpqrcode library

Here, we are using the QR Code library. PHP QR Code is open source library for generating QR Code, 2-dimensional barcode. For using this, first download the QR Code library from the Github -

Now create a PHP file in the same folder where you placed the phpqrcode folder. We need to include 'qrlib.php' file to use a function named 'png()'. This function is inside the QRcode class which outputs a QR code directly in the browser when we pass some text as a parameter.

Syntax

QRcode::png(text, file, ecc, pixel_size, frame_size);

text - the text message which needs to be in a QR code,
file - location to save the generated QR code,
ecc - to specify the error correction capability of the QR code, it has four levels: L, M, Q and H,
pixel_size - to specify the pixel size of QR,
frame_size - to specify the size of the QR.

Copy and paste the given code in your PHP file and replace the value in the content variable.

<?php
    include "phpqrcode/qrlib.php" ;
    $content = "http://www.etutorialspoint.com/" ;
    QRcode::png($content) ;
?>

When you execute the above code, you will get this QR Code.

QR Code

 

So, this is the way to access a brand's website more quickly by QR code scanner rather than manually entering an URL.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Programming Exercises

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How does PHP store data in cache?... >>
<< Fibonacci Series Program in PHP...