PHP Two-dimensional code generation, php_php tutorial

Source: Internet
Author: User

PHP Two-dimensional code generation, PHP


This article introduces two methods of generating QR code using PHP.
(1) Using Google to generate two-dimensional code open Interface, the code is as follows:

/**  * Google API qr code generation "QRCode can store up to 4,296 alphanumeric types of arbitrary text, you can view the QR code data format"  * @param string $data QR Code contains information, can be numbers, characters, Binary information, Chinese characters. Data types cannot be mixed and data must be UTF-8 url-encoded. If you need to pass more than 2K bytes of information, use the Post method  * @param int $widhtHeight to generate dimension settings for the QR code  * @param String $EC _level Optional error correction level, QR code supports four levels of error correction, used to recover lost, misread, blurred, data.  *       L-Default: can identify loss of 7% of data  *       M can identify loss of 15% of data  *       Q can identify lost 25% of the data  *       H can identify lost 30% of the data  * @ param int $margin The distance generated by the two-dimensional code from the picture border  */function Generateqrfromgoogle ($data, $widhtHeight = ' _level= ', $EC ' L ', $ margin= ' 0 ') {  $url =urlencode ($data);  

How to use:

The Post method implements a way to request the Google API to generate a two-dimensional code:

function QRCode ($width, $height, $string) {  $post _data=array ();  $post _data[' cht ']= ' QR ';  $post _data[' CHS ']= $width. " X ". $height;  $post _data[' CHL ']= $string;  $post _data[' Choe ']= "UTF-8";  $url = "Http://chart.apis.google.com/chart";  $data _array=array ();  foreach ($post _data as $key = + $value) {   $data _array[]= $key. ' = '. $value;  }  $data =implode ("&", $data _array);  $ch =curl_init ();  curl_setopt ($ch, Curlopt_post, 1);  curl_setopt ($ch, Curlopt_header, 0);  curl_setopt ($ch, Curlopt_url, $url);   curl_setopt ($ch, Curlopt_postfields, $data);  curl_setopt ($ch, Curlopt_returntransfer, 1);  $result =curl_exec ($ch);  echo ""; Note that you do not write the header  

How to use:

Of course, the resulting picture is the same as above.

(2) using the PHP QR code class library to generate two-dimensional code
Note using this class library must first download the class library package, download the address:
Address: http://phpqrcode.sourceforge.net/
There are many examples of downloaded compression packages, which can be researched by ourselves, and a simple use case is given below (the meaning of the parameters is the same as above):

<?php include "./phpqrcode.php"; $data = ' All rights reserved: Http://www.bkjia.com '; $errorCorrectionLevel = "L"; $matrixPointSize = "4"; QRCode::p ng ($data, False, $errorCorrectionLevel, $matrixPointSize);

The above is the whole content of this article, I hope that you can master the PHP production of two-dimensional code to be helpful.

http://www.bkjia.com/PHPjc/1062501.html www.bkjia.com true http://www.bkjia.com/PHPjc/1062501.html techarticle php qr code generation, PHP this article introduces two ways to generate QR codes using PHP. (1) Using Google to generate two-dimensional code open Interface, the code is as follows:/** * Google api qr code generation ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.