iCalendar TEXT 数据类型 - 使用 PHP 准备值

发布于 2024-11-10 17:14:02 字数 1105 浏览 1 评论 0原文

我正在提供我的应用程序事件的下载链接。我缺少的一件事是如何为 TEXT 数据准备值类型。具体来说,DESCRIPTION 属性最终的值具有 HTML。我已经下载了几个与 iCalendar RFC 相关的 PHP 项目,但我还没有找到用于准备 TEXT 值的良好代码片段。


我发现了一个博客条目可在 Google 缓存中使用具有换行功能,并且我注意到从 Outlook 2010 生成 ICS 文件具有换行功能,但我暂时先不考虑它,如果出现问题再回来处理它。

我还决定添加对不同可能的行结尾的支持:

/**
 * Prepare data for a TEXT field
 *
 * @param string $text
 * @return string
 */
public static function prepareText($text)
{
    $search = array('\\', ';', ',', "\r\n", "\n", "\r");
    $replace = array('\\\\', '\;', '\,', '\n', '\n', '\n');
    return str_replace($search, $replace, $text);
}

I am providing download links for my application's events. One piece I am missing is how to prepare values for the TEXT data type. Specifically, the value that will end up with the DESCRIPTION property has HTML. I have downloaded several PHP projects related to the iCalendar RFC, but I haven't tracked down a good snippet of code for preparing TEXT values.


I found a blog entry that was only available in Google Cache that had line wrapping, and I noticed that generating an ICS file from Outlook 2010 has line wrapping, but I'm going to leave it alone for now and come back to it if there's a problem.

I also decided to add support for the different possible line endings:

/**
 * Prepare data for a TEXT field
 *
 * @param string $text
 * @return string
 */
public static function prepareText($text)
{
    $search = array('\\', ';', ',', "\r\n", "\n", "\r");
    $replace = array('\\\\', '\;', '\,', '\n', '\n', '\n');
    return str_replace($search, $replace, $text);
}

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

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

发布评论

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

评论(1

木森分化 2024-11-17 17:14:02

请注意换行符的单引号和双引号的混合(双引号解释换行符,而单引号则不解释)

$text = 'Hello, World!
This is in a new line; after a semicolon/comma';
$search = array('/',';',',',"\N","\n");
$replace = array('\/','\;','\,','\n','\n');
$description = str_replace($search,$replace,$text);

print_r($description);

当然,这可以通过可能更简单的 RegExp 来完成。

Note the mixture of single and double quotes for the line break (Double quotes interpret the line breaks whereas single ones don't)

$text = 'Hello, World!
This is in a new line; after a semicolon/comma';
$search = array('/',';',',',"\N","\n");
$replace = array('\/','\;','\,','\n','\n');
$description = str_replace($search,$replace,$text);

print_r($description);

For sure this can be done with a probably easier RegExp..

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