The solution to the Chinese garbled code when the PHP is generated in two-dimensional _php tips

Source: Internet
Author: User
Tags php class vcard

This article illustrates the solution of Chinese garbled code when PHP generates two-dimensional codes. Share to everyone for your reference. The specific analysis is as follows:

Recently done a scan two-dimensional code to get a vcard project, encountered a problem, a part of the generated two-dimensional code, using the Android phone after scanning the Chinese name of the vcard is garbled, after the discovery, this part of the vcard org this type has no content, Immediately judged no content to add a fixed string, so garbled problem can be solved.

Several ways to generate two-dimensional code in PHP

1.google Open API, code as follows:

Copy Code code as follows:
$urlToEncode = "Http://www.jb51.net";
Generateqrfromgoogle ($urlToEncode);
function Generateqrfromgoogle ($chl, $widhtHeight = ' _level= ', $EC ' 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 two-dimensional code file

Copy Code code as follows:
QRCode::p ng (' Code data text ', ' filename.png ');

# Generate pictures to Browser

Copy Code code as follows:
QRCode::p ng (' 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

The 2nd method is to add a logo in the middle of the two-dimensional code to modify the PNG method in the Qrimage class in phpqrcode.php, the code is as follows:

Copy Code code 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);
}

PS: Interested friends can also refer to this station two-dimensional code tool: Http://tools.jb51.net/transcoding/jb51qrcode

I hope this article will help you with your PHP program design.

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.