I'm trying to generate QR codes on my website. All they have to do is have a URL in them, which a variable on my site will provide. What would be the easiest way to do this?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The phpqrcode library is really fast to configure and the API documentation is easy to understand.
In addition to abaumg's answer I have attached 2 examples in
PHP
from http://phpqrcode.sourceforge.net/examples/index.php1. QR code encoder
first include the library from your local path
then to output the image directly as PNG stream do for example:
to save the result locally as a PNG image:
2. QR code decoder
See also the zxing decoder:
http://zxing.org/w/decode.jspx
Pretty useful to check the output.
3. List of Data format
A list of data format you can use in your QR code according to the data type :
http://
)more data type on http://blog.thenetimpact.com/2011/07/decoding-qr-codes-how-to-format-data-for-qr-code-generators/
I know the question is how to generate QR codes using PHP, but for others who are looking for a way to generate codes for websites doing this in pure javascript is a good way to do it. The jquery-qrcode jquery plugin does it well.
The endroid/QrCode library is easy to use, well maintained, and can be installed using composer. There is also a bundle to use directly with Symfony.
Installing :
Usage :
It's worth adding that, in addition to the QR codes library posted by @abaumg, Google provides a
QR Codes APIQR Codes APImany thanks to @Toukakoukan for the link update.To use this , basically:
300x300
is the size of the QR image you want to generate,chl
is the url-encoded string you want to change into a QR code, andchoe
is the (optional) encoding.The link, above, gives more detail, but to use it just have the
src
of an image point to the manipulated value, like so:Demo:
The easiest way to generate QR codes with PHP is the phpqrcode library.
qrcode-generator on Github. Simplest script and works like charm.
Pros: