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
- // Brief description of api parameters
- // Choe is encoded. the default value is UTF-8.
- // Use post to send data larger than 2 k
- /*
- Chld error handling
- L: by default, 7% data loss can be restored.
- M: 15% allowed
- Q: 25% allowed
- H: 30% allowed
- */
- $ UrlToEncode = "http://9streets.cn ";
- GenerateQRfromGoogle ($ urlToEncode );
- Function generateQRfromGoogle ($ chlorophyll, $ widhtHeight = '000000', $ EC_level = 'l', $ margin = '0 ')
- {
- $ Url = urlencode ($ url );
- Echo '. $ widhtHeight. 'X '. $ widhtHeight. '& cht = qr & chld = '. $ EC_level. '| '. $ margin. '& chlorophyll = '. $ chlorophyll. '"alt =" QR code "widhtHeight = "'. $ size. '"widhtHeight = "'. $ size. '"/> ';
- }
Post method implementation:
Copy content from PHP Code to clipboard
- $ Width = 300;
- $ Height = 300;
- $ String = "";
- Function qrcode ($ width, $ height, $ string)
- {
- $ Post_data = array ();
- $ Post_data ['cht'] = 'QR ';
- $ Post_data ['chs '] = $ width. "x". $ height;
- $ Post_data ['check'] = $ string;
- $ Post_data ['choe'] = "UTF-8 ";
- $ Url = "http://chart.apis.google.com/chart ";
- $ Data_Array = array ();
- Foreach ($ post_data as $ key => $ value)
- {
- $ Data_Array [] = $ key. '='. $ value;
- }
- $ Data = implode ("&", $ data_Array );
- // Echo $ data;
- $ Ch = curl_init ();
- Curl_setopt ($ ch, CURLOPT_POST, 1 );
- Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
- Curl_setopt ($ ch, CURLOPT_URL, $ url );
- Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data );
- Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
- $ Result = curl_exec ($ ch );
- // Echo ""; note that the header is not written.
- Return $ result;
- }
- Header ("Content-type: image/png ");
- 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
-
- Include "./phpqrcode. php ";
- $ Value = "http://www.weste.net ";
- $ ErrorCorrectionLevel = "L ";
- $ MatrixPointSize = "4 ";
- QRcode: png ($ value, false, $ errorCorrectionLevel, $ matrixPointSize );
- Exit;
- ?>