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.