如何用PHP生成二维码? [英] How to Generate a QR code using PHP?

查看:0
本文介绍了如何用PHP生成二维码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

图书馆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��IDATK}��ő��|I����ʚt{oZ6,I�{�5몏{���Ϫ����/MIEND�B`�

编辑: 我已经尝试将html头文件更改为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生成二维码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆