如何使用PHP生成QR码?

时间:2018-03-27 17:31:42

标签: php qr-code

我正在尝试将某些数据转换为网页上的QR。要做到这一点,我使用'php qrcode'。

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

我无法使用该库生成QR码。我错过了PHP扩展。

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

brew install gd

当前代码:

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

当前输出:

PNGIHDRWWKK/PLTE U ~ IDAT8 ұ ұPG. N t t,V H,pe 4Ĵq k j “^ lphSn8D> 3T - %:\ Z4 {OL C-_O rrmx +,}ö|iʚt{oZ6 \,I {5몏{Ϫ/ MIENDB `

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

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

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

<?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框架

2 个答案:

答案 0 :(得分:0)

试试这个:

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

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

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

答案 1 :(得分:-1)

您可以使用phpqrcode库来使用,请访问this page

相关问题