iCalendar TEXT 数据类型 - 使用 PHP 准备值
我正在提供我的应用程序事件的下载链接。我缺少的一件事是如何为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意换行符的单引号和双引号的混合(双引号解释换行符,而单引号则不解释)
当然,这可以通过可能更简单的 RegExp 来完成。
Note the mixture of single and double quotes for the line break (Double quotes interpret the line breaks whereas single ones don't)
For sure this can be done with a probably easier RegExp..