Home > Backend Development > PHP Tutorial > PHP QR code generation code

PHP QR code generation code

WBOY
Release: 2016-07-25 09:00:19
Original
1385 people have browsed it
Isn’t it cool to use php to generate QR codes? This article introduces two methods to you. Friends in need, come and take a look.

Method 1, use google open api

<?php
/*
二维码
*/
$urlToEncode="http://bbs.it-home.org";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
 {
    $url = urlencode($url);
    echo '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.
'&chl='.$chl.'" alt="QR code" widhtHeight="'.$size.'" widhtHeight="'.$size.'"/>';
 }
?>
Copy after login

Method 2, use php library PHP QR Code

Class library download: http://sourceforge.net/projects/phpqrcode/ index.php in the class library is a demonstration example.

The following is an example written by myself.

<?php
/*
生成二维码
*/
 include('./phpqrcode.php');
   // 二维码数据
   $data = 'http://bbs.it-home.org.com';
   // 纠错级别:L、M、Q、H
   $errorCorrectionLevel = 'L';
    // 点的大小:1到10
   $matrixPointSize = 4;
   // 生成的文件名
   $path = "erwei/";
   if (!file_exists($path)){
        mkdir($path);
   }
   $filename = $path.$errorCorrectionLevel.'.'.$matrixPointSize.'.png';
   QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
   echo "<img  src='$filename' / alt="PHP QR code generation code" >";
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template