• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Generate QR code with meta data

Here is a simple function to generate Quick Response codes with simple meta data like text, phone number, email or URL.

This function takes 5 parameters: data to encode, type of meta, data to use(TXT for text, EMAIL for email, TEL for phone number and URL for a website link ), size of image in pixels, error correction level, margin.

function qr_code($data, $type = "TXT", $size ='150', $ec='L', $margin='0') 
    $types = array("URL" => "http://", "TEL" => "TEL:", "TXT"=>"", "EMAIL" => "MAILTO:");
    if(!in_array($type,array("URL", "TEL", "TXT", "EMAIL")))
        $type = "TXT";
    if (!preg_match('/^'.$types[$type].'/', $data)) 
        $data = str_replace("\", "", $types[$type]).$data;
    $ch = curl_init();
    $data = urlencode($data); 
    curl_setopt($ch, CURLOPT_URL, '');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $response = curl_exec($ch);

    return $response;
header("Content-type: image/png");
echo qr_code("", "URL");

You may also be interested in:

Powered by

blog comments powered by Disqus