PHP:iCal 创建,如何在描述中换行

发布于 2024-12-26 15:05:53 字数 1586 浏览 3 评论 0原文

我正在使用以下内容为 PHP 脚本创建 Outlook 日历邀请。然而 \n 并没有在 Outlook 中给我一个新行。有办法做到这一点吗?如果你不能的话,那就显得很愚蠢了!

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

$calEmail = '[email protected]';
$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:[email protected]
UID:12345678
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Yup:mailto:[email protected]
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";
}


  }

这是我遇到问题的 DESCRIPTION New \n Line 部分。

将不胜感激任何帮助

汤姆

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 = '[email protected]';
$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:[email protected]
UID:12345678
ATTENDEE;PARTSTAT=NEEDS-ACTION;RSVP= TRUE;CN=Yup:mailto:[email protected]
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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拥抱影子 2025-01-02 15:05:53

您应该将 \r\n 替换为 \n:

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

另请参阅在 iCal 文件中编码换行符

You should replace \r\n with \n:

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

See also Encoding newlines in iCal files

秋凉 2025-01-02 15:05:53

您可以使用 =0D=0A 作为具有适当编码的新行:

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

或替代方法(使用 base64):

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

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==
只怪假的太真实 2025-01-02 15:05:53

在 Windows 上,您可以使用 \r\n 创建新行。

更详细地说:

\r 在 ASCII 中是 CR 代表“回车”
ASCII 中的 \nLF 代表“换行”

Windows 需要两者的组合,而 Linux 系统只使用 \n

维基百科的换行符页面。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文