PHP生成二维码的方式有多种,可以利用google开放的API,可以利用php QR Code类库生成,本文着重介绍使用php QR Code类库来生成二维码.
1、代码包下载地址:http://sourceforge.net/projects/phpqrcode/
2、下载下来的压缩包里面有很多示例,可以自行研究,下面给出一个简单的使用案例,代码如下:
include "phpqrcode/phpqrcode.php"; $data='http://www.phprm.com'; $errorCorrectionLevel="L"; $matrixPointSize="4"; QRcode::png($data,false,$errorCorrectionLevel,$matrixPointSize);
官方法实例,代码如下:
<?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 ?>
3、有的二维码中间有图片,其实就是把图片拷贝到已经生成的二维码图片上.
利用google生成二维码的开放接口,代码如下:
<?php /** * google api 二维码生成【QRcode可以存储最多4296个字母数字类型的任意文本,具体可以查看二维码数据格式】 * @param string $data 二维码包含的信息,可以是数字、字符、二进制信息、汉字。不能混合数据类型,数据必须经过UTF-8 URL-encoded.如果需要传递的信息超过2K个字节,请使用POST方式 * @param int $widhtHeight 生成二维码的尺寸设置 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。 * L-默认:可以识别已损失的7%的数据 * M-可以识别已损失15%的数据 * Q-可以识别已损失25%的数据 * H-可以识别已损失30%的数据 * @param int $margin 生成的二维码离图片边框的距离 */ function generateQRfromGoogle($data, $widhtHeight = '150', $EC_level = 'L', $margin = '0') { $url = urlencode($data); echo '<img src="/static/imghwm/default1.png" data-src="http://chart.apis.google.com/chart?chs=' . $widhtHeight . 'x' . $widhtHeight . '&cht=qr&chld=' . $EC_level . '|' . $margin . '&chl=' . $data . '" class="lazy" widhtHeight="' . $widhtHeight . '" widhtHeight="' . $widhtHeight . '"/ alt="超简单PHP生成二维码实例 " >'; } ?>
调用方法,代码如下:
$data='版权所有:http://www.phprm.com/'; generateQRfromGoogle($data);
本文地址:
转载随意,但请附上文章地址:-)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
