Rumah  >  Artikel  >  pembangunan bahagian belakang  >  php qrcode 输出乱码怎么解决

php qrcode 输出乱码怎么解决

藏色散人
藏色散人asal
2021-07-15 09:26:432521semak imbas

php qrcode输出乱码的解决方法:首先打开相应的PHP文件;然后找到执行生成二维码的代码部分;最后在该代码后面添加“die;”或“exit;”即可。

php qrcode 输出乱码怎么解决

本文操作环境:Windows7 系统、PHP7.1版,DELL G3电脑

php qrcode 输出乱码怎么解决?

解决phpqrcode.php生成二维码输出到页面上出现乱码问题

先来看一下乱码:

 解决方法:

在执行生成二维码的那句代码之后添加die;exit;即可。如果还是不行,可以用编程工具把.php文件转为“UTF-8 无BOM编码格式

<?php
namespace app\index\controller;
use think\Cache;
use think\Controller;
use think\Db;
use think\Session;
use think\Request;
/**引入类库方式一(extend/phpqrcode.php)*/
import(&#39;phpqrcode&#39;, EXTEND_PATH);
/*
 *二维码生成API接口(对外)
 */
class Qr extends Jcb{
   
    public function api(){               
        if(!isset($_GET[&#39;text&#39;])){
            header("Content-type: text/html; charset=utf-8"); 
            echo &#39;参数错误.&#39;;
			exit;
        }
        $text = strtoupper(trim($_GET[&#39;text&#39;])); 
        //访问频率
        if(Cache::get($text)){
            header("Content-type: text/html; charset=utf-8");   
            echo &#39;请求频率太快,5秒内仅允许一次刷新&#39;;exit;            
        }else{
            Cache::set($text,&#39;1&#39;,$this->config[&#39;visit-interval&#39;]);
        }		
        //引入类库方式二(在vendor下创建phpqrcode目录,并且把phpqrcode.php文件放进去) 
        //Vendor(&#39;phpqrcode.phpqrcode&#39;); 
        $errorCorrectionLevel =intval(2) ;//容错级别 
        $matrixPointSize = intval(4);     //生成图片大小 
        $margin =1;                        //外边距离(白边)
        //方式一
        \QRcode::png($text,false, $errorCorrectionLevel, $matrixPointSize, 1); 
        //方式二
        //$qr = new \QRcode();  
        //$qr->png($text,false, $errorCorrectionLevel, $matrixPointSize, 1); 
        die;
    }
}

 最终效果图:

推荐学习:《PHP视频教程

Atas ialah kandungan terperinci php qrcode 输出乱码怎么解决. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:php 加密解密方法是什么Artikel seterusnya:php foreach怎么删除数组