【问题标题】:How do I insert new line in a variable to crate Qrcode如何在变量中插入新行以创建二维码
【发布时间】:2021-10-11 08:44:25
【问题描述】:

我正在尝试创建包含员工图片的名片二维码

        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 3 新行才能工作 我还需要添加新行来格式化名片

if ($photo64 != ''){
$text = $text.'PHOTO;TYPE=PNG;ENCODING=BASE64:
'.$photo64.' '. "\n".' '
. "\n".' '
. "\n".' ' ;
}

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

提前感谢您的帮助

【问题讨论】:

    标签: php


    【解决方案1】:

    您正在混淆字符串引用。由于要使用行返回\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 上找到。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多