教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php二维码程序的实现代码

php二维码程序的实现代码

发布时间:2016-05-26   编辑:jiaochengji.com
本文介绍下,用php实现二维码的一个例子,有需要的朋友,参考下吧。

php生成二维码可以有以下几种方式
1.google开放api
例子:
 

复制代码 代码示例:
<?php
//google api
$url="http://phperzj.sinaapp.com/";
echo cre_QR($url);
   function cre_QR($chl,$widhtHeight ='150',$EC_level='L',$margin='0'){
     $chl=urlencode($chl);
     $qr = '</pre>
<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$chl.'" alt="QR code" />
<pre>';
   return $qr;
}
?>

参数说明如下:
http://chart.apis.google.com/chart? : 调用 Google 图表 API
cht=qr :选择生产QR码
&chs=100×100 :尺寸大小
&chld=L|4 :L代表默认纠错水平; 4代表二维码边界空白大小,可自行调节。
&chl= :二维码内容
很贴心的是这个api支持get和post

2.php类库PHP QR Code
PHP QR Code is open source (LGPL) library for generating QR Code,
2-dimensional barcode. Based on libqrencode C library,
provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2).
Implemented purely in PHP, with no external dependencies (except GD2 if needed).
地址:http://phpqrcode.sourceforge.net/
下载:http://sourceforge.net/projects/phpqrcode/
说明:
To install simply 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)

Then use it as follows:
QRcode::png(‘code data text’, ‘filename.png’); // creates file
QRcode::png(‘some othertext 1234′); // creates code image and outputs it directly into browser
例子:
 

复制代码 代码示例:
<?php
//PHP QR CODE
//include("phpqrcode/qrlib.php");
include("phpqrcode/phpqrcode.php");
QRcode::png("http://phperzj.sinaapp.com");
?>

3.libqrencode

地址:http://fukuchi.org/works/qrencode/index.en.html
php支持请参考:http://hirokawa.netflowers.jp/entry/4900/

4.QRcode Perl CGI & PHP scripts
地址:http://www.swetake.com/qr/qr_cgi.html

您可能感兴趣的文章:
php数组排序方法大全(脚本学堂整理奉献)
PHP二维数组排序的函数
php数组去重(一维、二维数组去重)的简单示例
php调用google接口生成二维码实例
php数组随机排序示例
php 二维数组排序的两个例子
php实用快速排序算法的实例代码
php二维码程序的实现代码
php二维数组根据键名分组相加的实例代码
使用phpqrcode生成二维码

关键词: 二维码  二维码生成代码   
[关闭]
~ ~