Home >Backend Development >PHP Tutorial >Have fun with PHP and quickly generate QR codes
In the process of PHP program development, it is inevitable to implement the function of generating QR codes. After all, "QR codes" are a very popular coding method on mobile devices in recent years. As long as you scan it, you will see me. I want to show you the content, so if you want to know how to quickly generate a QR code, don’t miss this article!
Now let’s go straight to the topic [Fun with PHP and quickly generate QR codes]:
First of all, we need to introduce to you a good open source for generating QR codes in PHP. Library "phpqrcode"; you just download it and copy it to your project folder!
Then we directly write a PHP sample code to generate a QR code:
The code is as follows:
<?php // 引入qrlib文件 include 'phpqrcode/qrlib.php'; $text = "I love PHP"; // 使用png()生成二维码 QRcode::png($text);
Here we first introduce qrlib .php file, and then define a content you want to display "I love PHP", and finally generate a QR code through QRcode::png($text);;
The generated result is:
Now everyone, take out your mobile phone and scan it~
Is the scanned result "I love PHP"? Isn’t it very simple and fast!
Attention! In "phpqrcode" there is a file named "qrlib.php"
This file must be included in the code to use the file named "png()" function, which is located in the QRcode class; the png() function outputs a QR code directly in the browser when we pass some text as a parameter, but we can also create a file and store it.
The syntax is:
QRcode::png($text, $file, $ecc, $pixel_Size, $frame_Size);
This function accepts the five parameters mentioned above:
$text: This parameter gives the message that needs to be displayed in the QR code , which is a mandatory parameter.
$file: Specify the location to save the generated QR code.
$ecc: This parameter specifies the error correction capability of QR, which has 4 levels L, M, Q and H.
$pixel_Size: Specify the pixel size of the QR code.
$frame_Size: Specify the size of Qr, which is from level 1-10.
Finally, I would like to recommend the latest and most comprehensive "PHP Video Tutorial"~ Come and learn!
The above is the detailed content of Have fun with PHP and quickly generate QR codes. For more information, please follow other related articles on the PHP Chinese website!