Home >Backend Development >PHP Tutorial >Two PHP methods to generate QR codes_PHP tutorial
PHP generates QR codes. Personally, I think there are two most commonly used ones. 1. Generate using Google’s API, 2. Generate using PHP QR Code. The QR codes generated by both methods are very clear. Yes, the effect is good. The following explains how to implement these two methods respectively.
1. PHP uses google api to generate QR code online:
I won’t go into the introduction of this API. You can check it on Google’s official website. I believe everyone is paying attention to the specific code, as follows:
1
2$urlToEncode="http://www.csdn.net";//The URL to generate the QR code
3generateQRfromGoogle($urlToEncode);
4function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
5{
6 $url = urlencode($url);
7 echo '
';//Google API interface, if it fails, you can check the Google website for the latest interface
8}
9?>
2. Use PHP QR Code to generate QR code:
1
2include "phpqrcode.php";//Introduce PHP QR library file
3$value="http://www.csdn.net";
4$errorCorrectionLevel = "L";
5$matrixPointSize = "4";
6QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
7exit;
8?>
PHP QR Code is an open source PHP QR code open source class library, based on the libqrencode C library, and provides API code to create QR barcode images, supporting png and jpg formats. If you don’t have this library, you can download it here: PHP QR Code QR code generation library