PHP: iCal creations, how to make a new line in a description

心已入冬 提交于 2019-12-10 15:54:07

问题


I'm using the following to create a calendar invite for outlook for a php script. However the \n doesn't give me a new line in outlook. Is there a way to do this? Seems silly if you can't!

  function addToCalendar($calEmail, $calSubject, $calDesc) 
  {

$calEmail = 'freelance@skinzy.org';
$description = $calDesc;
$message="BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20110718T121000Z
DTEND:20110718T131000Z
DTSTAMP:20110525T075116Z
ORGANIZER;CN=TOMS TEST:mailto:system@skinzy.org
UID:12345678
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Yup:mailto:sample@test.com
DESCRIPTION New \n Line
LOCATION: I AM THE LOCATION
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY: TEST SUMMARY
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR";

$headers = "From: From Name <From Mail>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/calendar; method=REQUEST;\n";
$headers .= '        charset="UTF-8"';
$headers .= "\n";
$headers .= "Content-Transfer-Encoding: 7bit";


$subject = "Meeting Subject";
$subject = html_entity_decode($calSubject, ENT_QUOTES, 'UTF-8');


if(mail($calEmail, $calSubject, $message, $headers)) {

    echo "sent";
}else {
    echo "error";
}


  }

It's the DESCRIPTION New \n Line part i'm having issues with.

Any help will be greatly appreciated

Tom


回答1:


You should replace \r\n with \n:

$description = str_replace("\r\n", "\\n", $description);

See also Encoding newlines in iCal files




回答2:


On Windows you create a new line using \r\n.

To go into further detail:

\r in ASCII is CR standing for "Carriage Return"
\n in ASCII is LF standing for "Line Feed"

Windows requires the combination of both while Linux systems simply use \n.

There is tons of information (probably more then you'd ever be interested to know) on Wikipedia's Newline page.




回答3:


You can use =0D=0A for new line with the appropriate encoding:

DESCRIPTION;ENCODING=QUOTED-PRINTABLE:This is the first line.=0D=0AThe Second line.=0D=0AThe third line.

or an alternative approach (using base64):

DESCRIPTION;FMTTYPE=text/html;ENCODING=BASE64:PHA+Tm9ybWFsIDAgZmFsc2UgZmFsc2UgZmFsc2UgTWljcm9zb2Z0SW50ZXJuZXRFeHBsb3JlcjQ8L3A+DQo8YnIgY2xhc3M9ImNsZWFyIiAvPg==


来源:https://stackoverflow.com/questions/8855606/php-ical-creations-how-to-make-a-new-line-in-a-description

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!