php如何生成二维码,简单示例

php生成二维码,听上去复杂,无从下手,也许你找了好多方法,今天我就一个方法试试,我做了个小例子,大家可以作参考,也可以作补充哦

<?php
$urlToEncode="http://bbs.lewanchina.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.'"/>';
}
 
//生成二维码
require_once(dirname(dirname(dirname(__FILE__))).'/style/code/commons.php');
$errorCorrectionLevel ='L';    
$matrixPointSize = 6;
$upload_url = '/uploads/rcode/'.$number.'.png';
$filename = dirname(dirname(dirname(__FILE__))).$upload_url;
QRcode::png($number, $filename, $errorCorrectionLevel, $matrixPointSize, 2);  
?>
commons.php页面
<?php
    $root = dirname(dirname(dirname(__FILE__))).'/style/code/';
    include $root."qrconst.php";
    include $root."qrconfig.php";
    include $root."qrtools.php";
    include $root."qrspec.php";
    include $root."qrimage.php";
    include $root."qrinput.php";
    include $root."qrbitstream.php";
    include $root."qrsplit.php";
    include $root."qrrscode.php";
    include $root."qrmask.php";
    include $root."qrencode.php";
?>



这个例子我已经试过了,确实能生产二维码


你可能感兴趣的:(PHP,二维码,示例)