Web Development Blog

Generate QR Code with PHP Using Google API

 What is QR Code

QR Code is a matrix code (or two-dimensional bar code) created by Japanese corporation Denso-Wave in 1994. The "QR" is derived from "Quick Response", as the creator intended the code to allow its contents to be decoded at high speed.
 
Sample: (http://superiorwebsys.com is in this code)
 
 
How to Generate QR Code with PHP Using Google API
<?
$urlToEncode
="http://superiorwebsys.com";
generateQRwithGoogle($urlToEncode);
function 
generateQRwithGoogle($url,$widthHeight ='150',$EC_level='L',$margin='0') {
    
$url urlencode($url); 
    echo 
'<img src="http://chart.apis.google.com/chart?chs='.$widthHeight.
'x'.$widthHeight.'&cht=qr&chld='.$EC_level.'|'.$margin.
'&chl='.$url.'" alt="QR code" widthHeight="'.$widthHeight.
'" widthHeight="'.$widthHeight.'"/>';
}
?>
 
 
What are the Benefits of QR Code
 
With QR code mobile users can access website with more details about something, or a promotion from anywhere.

Associated tags:  PHP, Google, QR Code, Google API, API

Comments:

Davids wrote on March 23, 2011 at 10:47
width, not width. $size has not been defined.

Michaels wrote on March 24, 2011 at 10:18
Thanks David, I`ve updated the code, so it should not generate any warnings now.

Susannahs wrote on May 31, 2011 at 09:38
I`m not esaily impressed. . . but that`s impressing me! :)

rgnelsons wrote on June 1, 2011 at 11:20
I need to create custom qr codes. If I could save the image to a file I could loop through from mysql... How could I write the qr code to file?

Michael P.s wrote on June 1, 2011 at 12:06
Thanks for the question, I will create another blog post explaining how you can save remote files to your server using CURL.

Michael P.s wrote on June 1, 2011 at 12:17
You can field instructions on How to Save Image From Web with php here

The Click Whisperers wrote on June 17, 2011 at 21:36
The Google API has a problem in that you can`t get a version 1 QR code from 16 characters. It cuts off at 15. The chld argument isn`t followed exactly and there are problems with the margins. Overall I wouldn`t trust this API much. It`s better to do something like "PHP QR Code" that actually works correctly and will give you a 21x21 when its supposed to, instead of a harder to scan 25x25.

Michael P.s wrote on June 27, 2011 at 12:36
What API do you have in mind?

Muhammad Atiqs wrote on June 27, 2011 at 16:28
Hi i want to create a QR image, But i want that i will enter three URL to generate the QR Code image, means the three URL will generate one QR code image. As it possible? Regards! M Atiq

Artificial Colours Web Designs wrote on August 2, 2011 at 05:21
NIce and simple, will have to give this a go.

Michael Ps wrote on August 8, 2011 at 12:18
Re: Muhammad Atiq That should be posible. Let me know if it worked well for you.

Bneonss wrote on March 11, 2012 at 05:48
Generatet QR code by Google is a best easy way.

julian caldwells wrote on March 28, 2012 at 17:25
very good. Wrapped it for Code Igniter. Very cool.


tieuhos wrote on May 24, 2012 at 00:54
create QRcode via google very good.

Add Comment:

CAPTCHA