php - PHP QR Code 不会显示 UTF-8 字符
问题描述
我正在使用 PHP QR 码 ( http://phpqrcode.sourceforge.net ) 生成一个 QR 码 vCard。它有效,但不适用于巴西葡萄牙语字符。我找不到如何强制使用 UTF-8。
问题是 iOS 无法识别字符,请查看下面的屏幕截图(iOS 和 Android)。
<?php
include('phpqrcode/qrlib.php');
// how to build raw content - QRCode with detailed Business Card (VCard)
$tempDir = "";
// here our data
$name = 'João Carlos da Silva';
$sortName = 'da Silva;João Carlos';
$phone = '+55 (89) 2345-6789';
$phonePrivate = '+55 (94) 4521-3989';
$phoneCell = '+55 (66) 1234-5678';
$orgName = 'GH Construtora';
$email = 'emaildousuario@dominio.com.br';
// if not used - leave blank!
$addressLabel = 'Escritório';
$addressPobox = '';
$addressExt = '2º andar';
$addressStreet = 'Av. das Nações, 200';
$addressTown = 'Cidade';
$addressRegion = 'SP';
$addressPostCode = '18.902-100';
$addressCountry = 'Brasil';
// we building raw data
$codeContents = 'BEGIN:VCARD'."\n";
$codeContents .= 'VERSION:2.1'."\n";
$codeContents .= 'N:'.$sortName."\n";
$codeContents .= 'FN:'.$name."\n";
$codeContents .= 'ORG:'.$orgName."\n";
$codeContents .= 'TEL;WORK;VOICE:'.$phone."\n";
$codeContents .= 'TEL;HOME;VOICE:'.$phonePrivate."\n";
$codeContents .= 'TEL;TYPE=cell:'.$phoneCell."\n";
$codeContents .= 'ADR;TYPE=work;'.
'LABEL="'.$addressLabel.'":'
.$addressPobox.';'
.$addressExt.';'
.$addressStreet.';'
.$addressTown.';'
.$addressPostCode.';'
.$addressCountry
."\n";
$codeContents .= 'EMAIL:'.$email."\n";
$codeContents .= 'END:VCARD';
// generating
QRcode::png($codeContents, $tempDir.'026.png', QR_ECLEVEL_L, 7);
// displaying
echo '<img src="026.png" />';
解决方案
解决方案:二维码将 VCARD 版本设置为 2.1。我更改为 3.0,它现在可以在 iOS 和 Android 上完美运行。这不是编码问题。
$codeContents .= 'VERSION:3.0'."\n";
推荐阅读
- java - 如何通过标签找到 DialogFragment?
- mysql - MySQL 合并来自联合查询的记录
- python - Python 示例代码,我无法正确运行它(Python 编码,玩 Pi)
- python - 在 TKinter 中根据用户输入插入“输入”框
- android-studio - 将异步任务优先于 Web 视图
- sql - 雪花新手 - 带有连接和旋转值的 SQL 语句问题
- python - 如何在 sqlite3 中附加一列并用熊猫系列填充其值
- java - 从 PDImageXObject 获取图像大小
- sql - 发送电子邮件时打开的连接过多
- python - CreateProcessW failed error:2 ssh_askpass: posix_spawn: No such file or directory 主机密钥验证失败,远程服务器上的 jupyter notebook