Home > Article > Backend Development > QR code online generation of picture PHP source code_PHP tutorial
QR code is becoming more and more popular now. Here we introduce the QR code generation code of PHP at both ends, a section of use Google's open QR code API is used, and the other section uses the PHP QR Code QR code open source class library, which is very simple.
1. Use Google Chart API to generate QR code images
Google Chart API is a very powerful API, and generating QR codes is just a small function of it. Here we only introduce the QR code part. If you want to know more functions, you can log in to the official website address: http://code.google.com/intl/zh-CN/apis/chart/
The code is as follows:
$urlToEncode="http://www.weste.net";
generateQRfromGoogle($urlToEncode);
Function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
$url = urlencode($url);
echo '';
}
?>
Generated QR code image:
2. Use PHP QR Code to generate QR code images
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. It is powerful and very simple to use.
The demo code is as follows:
include "./phpqrcode/phpqrcode.php";
$value="http://www.weste.net";
$errorCorrectionLevel = "L";
$matrixPointSize = "4";
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
exit;
?>
Generated QR code image: