Php QR code generation methods

Source: Internet
Author: User
Php generates two-dimensional codes in several ways, which are easy to use and have been tested.

Php generates two-dimensional codes in several ways, which are easy to use and have been tested.
1. open interfaces using google
Method 1 of the get method:
 

Copy content from PHP Code to clipboard
  1. // Brief description of api parameters
  2. // Choe is encoded. the default value is UTF-8.
  3. // Use post to send data larger than 2 k
  4. /*
  5. Chld error handling
  6. L: by default, 7% data loss can be restored.
  7. M: 15% allowed
  8. Q: 25% allowed
  9. H: 30% allowed
  10. */
  11. $ UrlToEncode = "http://9streets.cn ";
  12. GenerateQRfromGoogle ($ urlToEncode );
  13. Function generateQRfromGoogle ($ chlorophyll, $ widhtHeight = '000000', $ EC_level = 'l', $ margin = '0 ')
  14. {
  15. $ Url = urlencode ($ url );
  16. Echo '. $ widhtHeight. 'X '. $ widhtHeight. '& cht = qr & chld = '. $ EC_level. '| '. $ margin. '& chlorophyll = '. $ chlorophyll. '"alt =" QR code "widhtHeight = "'. $ size. '"widhtHeight = "'. $ size. '"/> ';
  17. }

Post method implementation:
 

Copy content from PHP Code to clipboard
  1. $ Width = 300;
  2. $ Height = 300;
  3. $ String = "";
  4. Function qrcode ($ width, $ height, $ string)
  5. {
  6. $ Post_data = array ();
  7. $ Post_data ['cht'] = 'QR ';
  8. $ Post_data ['chs '] = $ width. "x". $ height;
  9. $ Post_data ['check'] = $ string;
  10. $ Post_data ['choe'] = "UTF-8 ";
  11. $ Url = "http://chart.apis.google.com/chart ";
  12. $ Data_Array = array ();
  13. Foreach ($ post_data as $ key => $ value)
  14. {
  15. $ Data_Array [] = $ key. '='. $ value;
  16. }
  17. $ Data = implode ("&", $ data_Array );
  18. // Echo $ data;
  19. $ Ch = curl_init ();
  20. Curl_setopt ($ ch, CURLOPT_POST, 1 );
  21. Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
  22. Curl_setopt ($ ch, CURLOPT_URL, $ url );
  23. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data );
  24. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
  25. $ Result = curl_exec ($ ch );
  26. // Echo ""; note that the header is not written.
  27. Return $ result;
  28. }
  29. Header ("Content-type: image/png ");
  30. Echo qrcode ($ width, $ height, $ string );

2. php QR Code library is used to implement
First download the class library package
Address: http://phpqrcode.sourceforge.net/
Download: http://sourceforge.net/projects/phpqrcode/
 

Copy content from PHP Code to clipboard
  1. Include "./phpqrcode. php ";
  2. $ Value = "http://www.weste.net ";
  3. $ ErrorCorrectionLevel = "L ";
  4. $ MatrixPointSize = "4 ";
  5. QRcode: png ($ value, false, $ errorCorrectionLevel, $ matrixPointSize );
  6. Exit;
  7. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.