Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of generating QR Code using php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the method of using php to generate QR code". In the daily operation, I believe that many people have doubts about the method of using php to generate QR code. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "using php to generate QR code". Next, please follow the editor to study!

This paper introduces two methods of using php to generate QR codes.

(1) use google to generate an open interface for QR codes, as follows:

/ * google api QR code generation [QRcode can store up to 4296 alphanumeric text. For more information, please see the QR code data format] * @ param string $data QR code contains information, such as numbers, characters, binary information, and Chinese characters. Cannot mix data types, data must pass through UTF-8 URL-encoded. If the information to be passed exceeds 2K bytes, use the POST method * @ param int $widhtHeight to generate the size setting of the QR code * @ param string $EC_level optional error correction level. The QR code supports four levels of error correction to recover lost, misread, ambiguous, and data. * L-default: 7% lost data can be identified * M-15% lost data can be identified * Q-25% lost data can be identified * H-30% lost data can be identified * @ param int $distance of the QR code generated by margin from the picture frame * / function generateQRfromGoogle ($data,$widhtHeight='150',$EC_level='L',$margin='0') {$url=urlencode ($data) Echo'

';}

How to use it:

Copyright $data=': https://www.jb51.net'; generateQRfromGoogle ($data)

The post method implements the way to request google api to generate a QR code:

Function qrcode ($width,$height,$string) {$post_data=array (); $post_data ['cht'] =' qr'; $post_data ['chs'] = $width. "x". $height; $post_data [' chl'] = $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); $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, do not write header return $result;}

How to use it:

Header ("Content-type:image/png"); $width=300; $height=300; $data='. All rights reserved: https://www.jb51.net';echo qrcode ($width,$height,$data)

Of course, the generated picture is the same as above.

(2) use php QR Code class library to generate QR code

Note that to use this class library, you must first download the class library package at the download address:

Address: http://phpqrcode.sourceforge.net/

There are many examples in the downloaded package, which you can study by yourself. Here is a simple use case (the meaning of the specific parameters is more or less the same as above):

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report