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; } }
最终效果图:
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)