PHP 解析 iCal 提醒字符串
我目前正在解析 iCal 提醒字符串,类似于: -P14DT0H0M0S
使用 PHP,我如何能够解析字符串的元素,以便如果我有:
<?
$reminder = "-P14DT0H0M0S" // somehow output to show "-2 weeks" or eve "-14 days"
// OR //
$reminder = "-P0DT3H0M0S" // somehow output to "-3 hours"
// etc...
对此的任何帮助都是伟大的。我有点不知道从哪里开始。
非常感谢!
I'm currently working on parsing iCal reminder strings, similar to: -P14DT0H0M0S
Using PHP, how might I be able to parse the elements of the string so that if I had:
<?
$reminder = "-P14DT0H0M0S" // somehow output to show "-2 weeks" or eve "-14 days"
// OR //
$reminder = "-P0DT3H0M0S" // somehow output to "-3 hours"
// etc...
Any help on this would be great. I'm kind of stuck on where to begin.
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉这种格式,几乎可以肯定有一个可用的库,但看起来一个简单的正则表达式就可以完成这里的工作。
像这样的东西:
I'm not familiar with the format, and there's almost certainly a library available for this, but it looks like a simple regex would do the job here.
Something like:
不确定您的项目背景或最终结果是什么,但这可能会有所帮助:
Not sure what the background of your project or your end result is, but this may help:
谷歌日历可以完全删除时间部分并返回类似“-P7D”的内容,所以我进行了调整
therefromhere 的正则表达式来处理这个问题。
Google calendar can drop time part completely and return something like '-P7D' so I have tweaked
therefromhere's regexp to deal with that.