ICS文件-使用PHP,希望插入换行符以将描述分成多个段落 [英] ICS file - using PHP, want to insert new line characters to break up description into paragraphs

查看:169
本文介绍了ICS文件-使用PHP,希望插入换行符以将描述分成多个段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP动态创建一个ICS文件,除了一个障碍外,它大部分"可以正常工作:

I'm creating an ICS file dynamically with PHP which is "mostly" working except for one snag:

在ICS文件的DESCRIPTION区域中,我想合并几个数据库字段并将它们分成自己的段落,这样当用户打开日历条目时,它们并没有全部被合并为一个字符串.

In the DESCRIPTION area of the ICS file, I want to concatentate several database fields and separate them into their own paragraphs so when the user opens the calendar entry, they're not all concatentated as one string.

我的问题是,如果我尝试使用换行符来连接这些字段,则"\ n"不会显示为Description内容的一部分.我打开了一个有效的ICS文件来完成此任务,该文件显示:

My problem is that if I try and concatenate these fields using the new line characters, the "\n" isn't showing up as part of the DESCRIPTION content. I've opened a valid ICS file that accomplishes this task and the file shows:

说明:1.单击此链接加入网络研讨会:\ n \ n https://www1.site.com/join /444/444444 \ n \ n \ n2.选择以下音频选项之一:\ n \ n

DESCRIPTION:1. Click this link to join the Webinar:\n\n https://www1.site.com/join/444/444444\n\n\n2. Choose one of the following audio options:\n\n

"\ n"是文件内容的一部分.但是,如果我尝试生成它,它会将\ n视为内容,而是ICS行的结尾:

The "\n" is part of the file content. But if I try and generate it, it treats the \n as not content, but the end of the line of the ICS line:

DESCRIPTION:line1

DESCRIPTION:line1

line2

因此ICS无法读取且无效.

So the ICS can't be read and isn't valid.

我尝试了很多组合,但似乎无法正常工作.似乎应该很简单,但事实并非如此.有什么想法吗?

I've tried many combinations, but can't seem to get this working. Seems like it should be simple, but isn't. Any ideas?

推荐答案

icalendar describe字段使用两个单独的字符"\"后跟"n"来表示换行符.如果您要使用这些字符编写 PHP字符串文字,则可以要么使用带单引号的字符串并简单地写\n,要么使用双引号并转义反斜杠,以使\n不会变成换行符.例如:

The icalendar DESCRIPTION field uses two separate characters, '\' followed by 'n' to represent line breaks. If you're writing a PHP string literal with those characters, you can either use a string with single quotes and simply write \n, or use double quotes and escape the backslash so that \n isn't turned into a newline character. For example:

$description = 'This is a description\nwith a newline';
// Or
$description = "This is a description\\nwith a newline";

您最终将如何完成操作取决于您的源代码,而我们尚未看到.

Exactly how you'll end up doing it depends on your source code, which we've not seen.

这篇关于ICS文件-使用PHP,希望插入换行符以将描述分成多个段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆