Home  >  Article  >  Backend Development  >  Solution to Chinese garbled characters when generating QR code in PHP, _PHP Tutorial

Solution to Chinese garbled characters when generating QR code in PHP, _PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:211159browse

Solution to the Chinese garbled code when php generates QR code,

The example in this article describes the solution to the problem of Chinese garbled characters when generating QR codes in PHP. Share it with everyone for your reference. The specific analysis is as follows:

Recently I did a project to scan a QR code to get a vcard. I encountered a problem. Some of the generated QR codes were scanned with an Android phone. The Chinese name in the vcard was garbled. After comparison, it was found that , the ORG type in this part of the vcard has no content, and then it is judged that there is no content and a fixed string is added, so that the problem of garbled characters can be solved.

Several ways to generate QR code in php

1.google open api, the code is as follows:

Copy the code The code is as follows:
$urlToEncode="http://www.bkjia.com";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
$url = urlencode($url);
echo '';
}

2.php class library PHP QR Code

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

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

Use case, the code is as follows:

# Create a QR code file

Copy code The code is as follows:
QRcode::png('code data text', 'filename.png');

# Generate images to browser

Copy code The code is as follows:
QRcode::png('some othertext 1234');

3.libqrencode

Address: http://fukuchi.org/works/qrencode/index.en.html

4.QRcode Perl CGI & PHP scripts

Address: http://www.swetake.com/qr/qr_cgi.html

In the second method, add the logo in the middle of the QR code and modify the png method in the QRimage class in phpqrcode.php. The code is as follows:

Copy code The code is as follows:
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $ saveandprint=FALSE, $mergePic='')
{
$image = self::image($frame, $pixelPerPoint, $outerFrame);
if($mergePic) {
$im = imagecreatefrompng($mergePic);
$w = imagesx($im);
$h = imagesy($im);
ImageAlphaBlending($image, true);
ImageAlphaBlending($im, true);
$qrw = (imagesx($image)-$w)/2;
$qrh = (imagesy($image)-$h)/2;
imagecopy($image, $im, $qrw, $qrh, 0, 0, $w, $h);
imagedestroy($im);
}
if ($filename === false) {
Header("Content-type: image/png");
ImagePng($image);
} else {
ImagePng($image, $filename);
if($saveandprint===TRUE){
header("Content-type: image/png");
ImagePng($image);
}
}
ImageDestroy($image);
}

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/929678.htmlTechArticleThe solution to the Chinese garbled code that appears when php generates a QR code. This article describes the example of the problem that occurs when php generates a QR code. Solution to Chinese garbled characters. Share it with everyone for your reference. Specific analysis is as follows...
Statement:
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