0

I am trying to create business card QRcode that contains employee picture

        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);

my problem is the \n is not working and it is necessary to add new lines the QR code works when the following section is commented (to remove the photo section) the photo section needs three \n 3 new lines to work also I will need to add new lines to format the business card

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

My problem is the php variable $text is giving me inline output and I need to separate the lines before using the QRcode function

Thanks in advance for help

1 Answers1

1

You are mixing up the string quoting. As you want to use a line return \n, it is best to keep the entire grouping in double quotes.

If I have understood what you want to do, I think this should work:

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

And you could / should possibly do this instead:

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

More details can be found on the PHP docs and even on Stack Overflow.

Tigger
  • 8,980
  • 5
  • 36
  • 40
  • Thanks that was very useful now I created a working vcf file successfully but I have the problem mentioned here https://stackoverflow.com/questions/39569202/php-qrcode-generation-failed – Mohamed Ayman Ragab Oct 11 '21 at 14:55