您的位置:首页 > 编程语言 > PHP开发

如何用PHP生成二维码实例

2015-07-10 10:46 671 查看
PHP常用有二种生成方法,可以利用google开放的API,可以利用php QR Code类库生成。

我用的是后者,现在来介绍一下用法

1、代码包下载地址:http://sourceforge.net/projects/phpqrcode/

2、项目直接访问index.php,会出现下面的页面

3、给一个简单的例子

include "phpqrcode/phpqrcode.php";
$data='http://www.111cn.net';
$errorCorrectionLevel="L";
$matrixPointSize="4";
QRcode::png($data,false,$errorCorrectionLevel,$matrixPointSize);


4、官方实例

<?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 cache
and 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
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: