Home php教程 php手册 php生成二维码中文乱码问题解决方法

php生成二维码中文乱码问题解决方法

Jun 02, 2016 am 09:14 AM

最近做了个扫描二维码得到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 ''; 
}
Copy after login

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方法,代码如下:

<?php
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE, $mergePic = &#39;&#39;) {
    $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);
}
Copy after login


永久链接:

转载随意!带上文章地址吧。

Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)