PHP generated two-dimensional code when there is a Chinese garbled solution,
In this paper, we explain the solution of the Chinese garbled characters when PHP generates the QR code. Share to everyone for your reference. The specific analysis is as follows:
Recently made a scan QR code to get a vcard project, encountered a problem, there is a part of the generated QR code, the Android phone scan to get a vcard in the Chinese name is garbled, after comparison to find, this part of the vcard in the type of org is not content, Immediately judge no content to add a fixed string, so the problem of garbled can be resolved.
Several ways to generate two-dimensional code in PHP
1.google Open API, the code is as follows:
Copy the Code code as follows: $urlToEncode = "http://www.bkjia.com";
Generateqrfromgoogle ($urlToEncode);
function Generateqrfromgoogle ($chl, $widhtHeight = ' Max ', $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 two-dimensional code file
Copy the code as follows: QRCode::p ng (' Code data text ', ' filename.png ');
# Generate image to browser
Copy the 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
In the 2nd method, add the logo to the middle of the QR code, modify the PNG method in the Qrimage class in phpqrcode.php, and the code is as follows:
Copy the Code Code as follows: public static function png ($frame, $filename = False, $pixelPerPoint = 4, $outerFrame = 4, $saveandprin T=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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/929678.html www.bkjia.com true http://www.bkjia.com/PHPjc/929678.html techarticle PHP generated two-dimensional code when the Chinese garbled solution, the example of this article on PHP generated two-dimensional code when the Chinese garbled solution. Share to everyone for your reference. A specific analysis such as ...