Simple php qr code generation instance

Source: Internet
Author: User

Php qr code generationThere are many ways to generate a QR Code by using APIs opened by google and the php QR Code library. This article focuses on using the php QR Code library to generate a QR Code.
1. Code package download address: http://sourceforge.net/projects/phpqrcode/
2. There are many examples in the downloaded compressed package. You can study it on your own. The following is a simple example:

The code is as follows: Copy code

Include "phpqrcode/phpqrcode. php ";
$ Data = 'http: // www.111cn.net ';
$ ErrorCorrectionLevel = "L ";
$ MatrixPointSize = "4 ";
QRcode: png ($ data, false, $ errorCorrectionLevel, $ matrixPointSize );

Official method instance

The code is as follows: Copy code

<? Php
# Include one of the two files:
/*
Qrlib. php for full version (also you have to provide all library files
Form package plus cache dir)

OR phpqrcode. php for merged version (only one file,
But slower and less accurate code because disabled cache
And quicker masking configured)
*/
# Two sentences:
# Put qrlib. php together with other files: files and folders.
# Phpqrcode. php is a merged version. You only need to include this file, but the generated image is slow and inaccurate.
# The following two usage methods are provided:

# Create a QR code file
QRcode: png ('code data text', 'filename.png ');
// Creates file

# Generating images to the browser
QRcode: png ('Some othertext 1234 ');
// Creates code image and outputs it directly into browser
?>

3. Some QR codes have images in the middle. In fact, you can copy the images to the generated QR code.


Use google to generate an open interface for QR code. The code is as follows:

The code is as follows: Copy code

/**
* Google api QR code generation [QRcode can store any text of a maximum of 4296 letters/numbers. For details, see the QR code data format]
* @ Param string $ information contained in the data QR code, which can be numbers, characters, binary information, and Chinese characters. The data type cannot be mixed and must pass through the UTF-8 URL-encoded. If the information to be passed exceeds 2 K bytes, use the POST method
* @ Param int $ widhtHeight: set the size of the generated QR code
* @ Param string $ EC_level: the error correction level is optional. The QR code supports four levels of error correction, which is used to restore lost, read, fuzzy, and data.
* L-default: 7% of lost data can be identified.
* M-identifies 15% of data loss
* Q-identifies 25% of data loss
* H-identifies 30% of data loss
* @ Param int $ the distance between the QR code generated by margin and the image border
*/
Function generateQRfromGoogle ($ data, $ widhtHeight = '000000', $ EC_level = 'l', $ margin = '0 '){
$ Url = urlencode ($ data );
Echo ' ';
}

Call method

The code is as follows: Copy code

$ Data = 'copyright: http://www.111cn.net /';
GenerateQRfromGoogle ($ data );

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.