gpt4 book ai didi

php - 如何使用 PHP 生成二维码?

转载 作者:行者123 更新时间:2023-12-05 08:08:28 27 4
gpt4 key购买 nike

我正在尝试将一些数据转换为网页上的二维码。为此,我使用“php 二维码”。

图书馆的 Sourceforge 主页:http://phpqrcode.sourceforge.net/

我无法使用库生成二维码。我缺少 PHP 扩展吗?

以为我错过了 GD2 扩展,我做到了:

brew install gd

当前代码:

  include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );

当前输出:

�PNG IHDRWWKK/PLTE���U���~�IDAT8����PG.�N�t�tـ,V��H,pe�����4Ĵq�k���j� ��'^l������p��h��Sn��8D>3T-��%����:\��z����4{oL��!C��-����_o. r����r��m����x+��,}��ő��|i����ʚt{oZ6\,i��{��5몏{����Ϫ����/MIEND��B `�

编辑:我试过将 html header 更改为 image/png。相同的结果。

   <meta http-equiv="content-type" content="image/png" charset="UTF-8">

编辑:完整的示例代码,相同的结果,没有二维码。

<?php header('Content-type: image/png'); ?>

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta http-equiv="content-type" content="image/png" charset="utf-8">
<title></title>
</head>
<body>

<?php

include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );

?>

</body>
</html>

编辑:以下显示相同的结果

<?php
header('Content-type: image/png');

include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
?>

编辑:使用 laravel 框架

最佳答案

试试这个:

<?php
header('Content-Type: image/png');

include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
?>

输出图像时,不需要 HTML 标签。或者,您可以将 img 标记与 data:... 源一起使用。有关示例,请参阅 here .

关于php - 如何使用 PHP 生成二维码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49519102/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com