雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

在TP中生成二维码图片出现乱码

2024-08-24 28

1. 在TP生成二维码图片出现乱码问题

composer require endroid/qr-code
<?phpnamespace app\index\controller;use Endroid\QrCode\QrCode;class Index{    public function index()    {        $qrCode = new QrCode('https://itqaq.com');        header('Content-Type: ' . $qrCode->getContentType());        $qrCode->setSize(200);//设置图片宽高, 默认320x320        $qrCode->setMargin(10);// 二维码上下右左四个方向的外边距        echo $qrCode->writeString();//显示二维码    }}

2. 通过百度找到解决方案

在输出二维码之前添加以下内容

ob_end_clean(); //清空缓冲区并将缓冲区关闭, 但不会输出内容
<?phpnamespace app\index\controller;use Endroid\QrCode\QrCode;class Index{    public function index()    {        $qrCode = new QrCode('https://itqaq.com');        header('Content-Type: ' . $qrCode->getContentType());        $qrCode->setSize(200);//设置图片宽高, 默认320x320        $qrCode->setMargin(10);// 二维码上下右左四个方向的外边距        ob_end_clean(); //解决TP二维码输出乱码        echo $qrCode->writeString();//显示二维码    }}

更新于:26天前
赞一波!4

文章评论

全部评论