How To Create A QRCode Using Google QRCode API In PHP

google qrcode api

Getting Started

I’ve used Bootstrap in this tutorial which is a CSS framework and is included in the downloadable of this tutorial, but if you want, you may download Bootstrap using this link.

Creating a QR Code

QR Code will be generated as an image, and it will look something like this:

<img src="$code&choe=UTF-8">


cht=qr Required Specifies a QR code.
chs= Required Image size.
chl= Required The data to encode. Data can be digits (0-9), alphanumeric characters, binary bytes of data, or Kanji.
choe= Optional How to encode the data in the QR code.

For additional info, you may visit Google’s documentation on QR Code using this link.

Creating a Script

To provide a working example, let’s create a form and generate a QR Code on the inputted text. Please create a new file, name it as index.php and paste the codes below.

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>How to Create a QRCode using Google QRCode API</title>
    <link rel="stylesheet" type="text/css" href="">
<div class="container">
    <h1 class="page-header text-center">QRCode using Google QRCode API</h1>
    <div class="row">
        <div class="col-sm-3 col-sm-offset-3">
            <form method="POST">
                <div class="form-group">
                    <label for="">Text to Convert to QRCode</label>
                    <input type="text" class="form-control" name="text_code">
                <button type="submit" class="btn btn-primary" name="generate">Generate QRCode</button>
        <div class="col-sm-3">
                    $code = $_POST['text_code'];
                    echo "
                        <img src="$code&choe=UTF-8">

That ends this tutorial. Happy Coding!

Download Here

Sharing is caring!

Facebook Comments

Leave a Reply