<?php
$tmp = isset($_GET['name'])?$_GET['name']:'';
if(empty($tmp)){
$urlToEncode='http://www.navidog.cn';
}else{
$urlToEncode = $tmp;
}
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 ='100',$EC_level='L',$margin='0')
{
echo 'Your enter url:'.$chl.'<br>';
$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.'"/>';
}
?>