PHP生成二维码的2种形式

WBOY
Release: 2016-06-13 11:55:41
Original
809 people have browsed it

PHP生成二维码的2种方式

微笑二维码的用处俺也就不说了,看一下用PHP生成的二维码吧。

利用谷歌提供的API 生成二维码,现在很多国外网站都提供了这类API

看下代码吧《=======================》

<?php $urlToEncode="http://gz.altmi.com"; 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
上面的方式特别的简便,但是如果人家网站不提供这种API 了,我们岂不是要歇菜了么?还是用我们的PHP 类库吧

php类库PHP QR Code
地址:http://phpqrcode.sourceforge.net/
下载:http://sourceforge.net/projects/phpqrcode/

实例:

<?php include('./phpqrcode/phpqrcode.php');    // 二维码数据    $data = 'http://gz.altmi.com';    // 生成的文件名    $filename = $errorCorrectionLevel.'|'.$matrixPointSize.'.png';    // 纠错级别:L、M、Q、H    $errorCorrectionLevel = 'L';     // 点的大小:1到10    $matrixPointSize = 4;     QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); ?>
Copy after login
官方给出的用例:<?php # include这两个文件之一:/*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 cacheand quicker masking configured)*/# 两句话解释:# 包含qrlib.php的话需要同其它文件放到一起:文件、文件夹。# phpqrcode.php是合并后版本,只需要包含这个文件,但生成的图片速度慢而且不太准确# 以下给出两种用法:# 创建一个二维码文件QRcode::png('code data text', 'filename.png');// creates file# 生成图片到浏览器QRcode::png('some othertext 1234');// creates code image and outputs it directly into browser
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