首页 > 解决方案 > 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" />';

安卓 iOS

标签: phpqr-codevcf-vcard

解决方案


解决方案:二维码将 VCARD 版本设置为 2.1。我更改为 3.0,它现在可以在 iOS 和 Android 上完美运行。这不是编码问题。

$codeContents .= 'VERSION:3.0'."\n";

推荐阅读