1 $todoString="www.maomii.com";
2 generateQRfromGoogle($todoString);
3
4 /**
5 * google api 最多4296个字符
6 * @param string $str 二维码包含的信息,数据须经过UTF-8 URL-encoded.如果需要传递的信息超过2K个字节,请使用POST方式
7 * @param int $widhtHeight 生成二维码的尺寸设置
8 * @param string $EC_level 可选纠错级别,QR码支持四个等级纠错,用来恢复丢失的、读错的、模糊的、数据。
9 * L-默认:可以识别已损失的7%的数据
10 * M-可以识别已损失15%的数据
11 * Q-可以识别已损失25%的数据
12 * H-可以识别已损失30%的数据
13 * @param int $margin 生成的二维码离图片边框的距离
14 */
15 function generateQRfromGoogle($str,$widhtHeight ='150',$EC_level='L',$margin='0')
16 {
17 $str = urlencode($str);
18 echo '<img src="http://chart.apis.google.com/chart?chs='.$widhtHeight.'x'.$widhtHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$str.'" alt="QR code" widhtHeight="'.$widhtHeight.'" widhtHeight="'.$widhtHeight.'"/>';
19 }
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Insert title here</title>
6 </head>
7 <body>
8 <div id="showEWM"></div>
9 <script type="text/javascript">
10 document.getElementById("showEWM").innerHTML = "<img src='http://chart.apis.google.com/chart?cht=qr&&chs=550x500&chl="+window.location.href+"'/>"
11 </script>
12 </body>
13 </html>