好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php qrcode 输出乱码怎么解决

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

本文操作环境: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('phpqrcode', EXTEND_PATH);
/*
 *二维码生成API接口(对外)
 */
class Qr extends Jcb{
   
    public function api(){
   if(!isset($_GET['text'])){
  header("Content-type: text/html; charset=utf-8"); 
  echo '参数错误.';
			exit;
   }
   $text = strtoupper(trim($_GET['text'])); 
   //访问频率
   if(Cache::get($text)){
  header("Content-type: text/html; charset=utf-8");   
  echo '请求频率太快,5秒内仅允许一次刷新';exit;  
   }else{
  Cache::set($text,'1',$this->config['visit-interval']);
   }		
   //引入类库方式二(在vendor下创建phpqrcode目录,并且把phpqrcode.php文件放进去) 
   //Vendor('phpqrcode.phpqrcode'); 
   $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视频教程》

以上就是php qrcode 输出乱码怎么解决的详细内容!

查看更多关于php qrcode 输出乱码怎么解决的详细内容...

  阅读:39次