首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在变量中插入新行以创建Qrcode

如何在变量中插入新行以创建Qrcode
EN

Stack Overflow用户
提问于 2021-10-11 08:44:26
回答 1查看 41关注 0票数 0

我正在尝试创建包含员工照片的名片QRcode

代码语言:javascript
复制
        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新行才能工作我还需要添加新行来格式化名片

代码语言:javascript
复制
if ($photo64 != ''){
$text = $text.'PHOTO;TYPE=PNG;ENCODING=BASE64:
'.$photo64.' '. "\n".' '
. "\n".' '
. "\n".' ' ;
}

我的问题是,在使用QRcode函数之前,php变量$text给我提供了内联输出,并且我需要分隔这些行。

提前感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2021-10-11 08:58:50

您混淆了字符串引号。由于您希望使用行返回\n,因此最好将整个分组保留在double quotes中。

如果我理解了你想要做什么,我想这应该行得通:

代码语言:javascript
复制
if ($photo64 != ''){
    $text = $text."PHOTO;TYPE=PNG;ENCODING=BASE64:\n".$photo64." \n \n \n";
}

你可以/应该这样做:

代码语言:javascript
复制
if ($photo64 != ''){
    $text = "${text}PHOTO;TYPE=PNG;ENCODING=BASE64:\n${photo64} \n \n \n";
}

更多细节可以在PHP docs甚至Stack Overflow上找到。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69523356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档