Generate QR code using PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:39:06
Original
1305 people have browsed it

Introduction: Today, when QR codes are widely used, automatically generating corresponding QR codes in web sites is the most basic requirement. The article introduces three ways to automatically generate QR codes using PHP.




Get method implementation method 1:

$urlToEncode="163.com";

generateQRfromGoogle($urlToEncode);

function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0') {

$url = urlencode($url);

return 'QR code';

}

Post method implementation:

$width = 300;

$height = 300;

$string = "163.com";

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);

//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. Use the php class library PHP QR Code to implement

First download the class library package

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

Download: http://sourceforge.net/projects/phpqrcode/

  • API Documentation

  • Detailed example

include "./phpqrcode/phpqrcode.php";

$value="http://www.weste.net";

$errorCorrectionLevel = "L";

$matrixPointSize = "4";

QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);

exit;

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735051.htmlTechArticleIntroduction: Today, when QR codes are widely used, the corresponding QR code is automatically generated in a web site. The most basic needs. The article introduces three ways to automatically generate QR codes using PHP. ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template