search
Homephp教程php手册php生成二维码中文乱码怎么办

php生成二维码中文乱码怎么办

Jun 13, 2016 am 09:29 AM
phpvcindivualChineseGarbled characterswhat to doscanninggeneratecode

php生成二维码中文乱码怎么办

   最近做了个扫描二维码得到vcard的项目,遇到一个问题,有一部分生成完的二维码,用android系统手机扫描后得到的vcard中的中文姓名是乱码,经过比对发现,这部分vcard中ORG这个类型没有内容,随即判断没内容就加上一个固定的字符串,这样乱码的问题得以解决。这样解决算是曲线救国吧,不知道怎么根本解决乱码问题,谁得到方法请留言告知,谢谢。

  三、 php生成二维码的几种方式

  1.google开放api

 代码如下  

$urlToEncode="http://gz.altmi.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

  php支持请参考:http://hirokawa.netflowers.jp/entry/4900/

  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);
}

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),