我正在尝试创建包含员工照片的名片QRcode
if (file_exists($employeeBCpicture)) {
$imagedata = file_get_contents($employeeBCpicture);
$photo64 = base64_encode($imagedata);
}else {//echo 'No<br>';
}
// QR bind_textdomain_codeset
//Include the necessary library for Ubuntu
include_once('/usr/share/phpqrcode/qrlib.php');
//Set the data for QR
$text =
'BEGIN:VCARD'. "\n".
'VERSION:2.1.'. "\n".'
N:'.ucwords($rowe['lname']).';'.ucwords($rowe['fname']).';;;'. "\n".'
FN:'. $fullname. "\n".'
TEL;WORK:+'.$phoneline. "\n".'
TEL;CELL:+'.$mobile. "\n".'
EMAIL;WORK:'.$email. "\n".'
URL;WORK:'.$website. "\n".'
ORG:'.ucwords($rowc['companyname']). "\n".'
TITLE:'.$title. "\n".'
ADR;WORK:;;'.$address.';;'. "\n";
if ($photo64 != ''){
$text = $text.'PHOTO;TYPE=PNG;ENCODING=BASE64:
'.$photo64.' '. "\n".' '
. "\n".' '
. "\n".' ' ;
}
$text = $text.'
END:VCARD';
//Set the filename with unique id
//echo $text.'<br>';
$rfilename = '../../../signatures/'.uniqid().".png";
//Set the error correction Level('L')
$e_correction = 'L';
//Set pixel size
$pixel_size = 2;
//Set the frame size
$frame_size = 2;
//Generates QR image
QRcode::png($text, $rfilename, $e_correction, $pixel_size, $frame_size);我的问题是\n不起作用,需要添加新行二维码可以工作当下面的部分被注释时(删除照片部分)照片部分需要三个\n新行才能工作我还需要添加新行来格式化名片
if ($photo64 != ''){
$text = $text.'PHOTO;TYPE=PNG;ENCODING=BASE64:
'.$photo64.' '. "\n".' '
. "\n".' '
. "\n".' ' ;
}我的问题是,在使用QRcode函数之前,php变量$text给我提供了内联输出,并且我需要分隔这些行。
提前感谢您的帮助
发布于 2021-10-11 08:58:50
您混淆了字符串引号。由于您希望使用行返回\n,因此最好将整个分组保留在double quotes中。
如果我理解了你想要做什么,我想这应该行得通:
if ($photo64 != ''){
$text = $text."PHOTO;TYPE=PNG;ENCODING=BASE64:\n".$photo64." \n \n \n";
}你可以/应该这样做:
if ($photo64 != ''){
$text = "${text}PHOTO;TYPE=PNG;ENCODING=BASE64:\n${photo64} \n \n \n";
}更多细节可以在PHP docs甚至Stack Overflow上找到。
https://stackoverflow.com/questions/69523356
复制相似问题