简体   繁体   中英

php QR code - Shows text instead of image

I'm trying to get a QR code working.

when i run it like:

<?php
include 'phpqrcode/qrlib.php';

QRcode::png('hwllo');
?>

it's working. However if i run it with some other php code

<?php
include 'phpqrcode/qrlib.php';

echo 'Hello world';

QRcode::png('hwllo');
?>

it displays:

Hello world‰PNG IHDRWWKK/PLTEÿÿÿUÂÓ~²IDAT8ÍÒ1„ Ðo(èô&^ƒŽ+0r¸× ávÆYbÖÝ-phêM÷ùð´ˆLHD'qá‚XÁZ'ç“Ë › š¶H CX™¾ª.ùú½¥êsUT<±eqhÖy|áÓÃ;š¶¼wž3d„D8÷ŠÈ—*ÀøÌEEÆgãL \\ú4a_ÀZ§UŠãúw¶35l|ìër_Lë•¡ê'ßQœçgÍü#Ãò¡IEND®B

You can't put text like that inside an image, it will make it malformed/corrupted and not display. Use your previous code and do no echo anything out inside the image. If you need to put text next to the image use HTML and link to the QR image file using an IMG tag as you would a normal image file for an HTML page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM