php生成二维码时出现中文乱码的解决方法,
本文实例讲述了php生成二维码时出现中文乱码的解决方法。分享给大家供大家参考。具体分析如下:
最近做了个扫描二维码得到vcard的项目,遇到一个问题,有一部分生成完的二维码,用android系统手机扫描后得到的vcard中的中文姓名是乱码,经过比对发现,这部分vcard中ORG这个类型没有内容,随即判断没内容就加上一个固定的字符串,这样乱码的问题得以解决.
php生成二维码的几种方式
1.google开放api,代码如下:
复制代码 代码如下:
$urlToEncode="http://www.bkjia.com";
generateQRfromGoogle($urlToEncode);
function generateQRfromGoogle($chl,$widhtHeight ='150',$EC_level='L',$margin='0')
{
$url = urlencode($url);
echo '';
}
2.php类库PHP QR Code
地址:http://phpqrcode.sourceforge.net/
下载:http://sourceforge.net/projects/phpqrcode/
用例,代码如下:
# 创建一个二维码文件
复制代码 代码如下:
QRcode::png('code data text', 'filename.png');
# 生成图片到浏览器
复制代码 代码如下:
QRcode::png('some othertext 1234');
3.libqrencode
地址:http://fukuchi.org/works/qrencode/index.en.html
4.QRcode Perl CGI & PHP scripts
地址:http://www.swetake.com/qr/qr_cgi.html
第2种方法中在二维码中间加上logo,修改phpqrcode.php中的QRimage类里的png方法,代码如下:
复制代码 代码如下:
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);
}
希望本文所述对大家的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software