《PHP生成二維碼的兩種方法》要點:
本文介紹了PHP生成二維碼的兩種方法,希望對您有用。如果有疑問,可以聯系我們。
1、采用GOOGLE API:
不推薦這種方法,因為網絡原因執行效率不穩定。
調用方法:
$urlToEncode="name:劉昕明,phone:18792448443";
generateQRfromGoogle($urlToEncode);
函數代碼:
/** * google api 二維碼生成【QRcode可以存儲最多4296個字母數字類型的任意文本,具體可以查看二維碼數據格式】 * @param string $chl 二維碼包含的信息,可以是數字、字符、二進制信息、漢字。不能混合數據類型,數據必須經過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($chl,$widhtHeight ='150',$EC_level='L',$margin='0') { $chl = urlencode($chl); 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="'.$widhtHeight.'" widhtHeight="'.$widhtHeight.'"/>'; }
也可參考本文附文的一個調用示例類。
2、生成二維碼的PHP類庫:
推薦TCPDF類包中附有2dbarcodes.php類。可以直接使用。
其它類庫有:
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/
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
轉載請注明本頁網址:
http://www.fzlkiss.com/jiaocheng/28.html