Generate QR Codes with php (EASY)

Generate QR Codes with php (EASY)

There you go, a function that will generate a QR Code with the help of a function hosted on the Google API servor.

function generate_qr($url, $size ='150', $imgsize = false, $EC_level='L', $margin='0') {
    $url = urlencode($url);
    return '<img src="'.$size.'x'.$size.&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$url.'" alt="QR code" width="'.($imgsize ? $imgsize : $size).'" height="'.($imgsize ? $imgsize : $size).'" />';

You call it like this:

<?php echo generate_qr(''); ?>

And get something like this: qr code

Try pointing your favorite code reader at it!

PS: I just noticed that it doesn’t work well because of the dark background, try it here.

If you liked this post think about subscribing to my RSS feed and prevent missing anything interesting. It's free, fast and doesn't hurt. Promise. Click here.
Related posts: