Encoding newlines in iCal files

后端 未结 7 1790
别那么骄傲
别那么骄傲 2020-12-14 05:41

I\'m trying to figure out how to encode newlines in the DESCRIPTION part of an iCal file in such a way that they will import properly into Outlook, Google Calendar and the A

相关标签:
7条回答
  • 2020-12-14 06:04

    This is my answer for DESCRIPTION

    $filev = str_replace("\r\n", '\\n', $p);
    $filev = str_replace("<br>",'\\n',$filev);
    $filev = (str_replace(";","\;",str_replace(",",'\,',$filev)));
    
    0 讨论(0)
  • 2020-12-14 06:07

    I had to escape the output in the string to set a literal "\n" in the output file. Like so. Worked a charm.

    $events .= "DESCRIPTION:" . str_replace("\n","\\n",str_replace(";","\;",str_replace(",",'\,',get_event_contents()))) . "\n";
    
    0 讨论(0)
  • 2020-12-14 06:10

    The comment with the link to the RFC from Matthew Bucket above in the original post helped me. Quoting from there:

    A BACKSLASH character in a "TEXT" property value MUST be escaped with another BACKSLASH character

    So, I did a

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

    and it worked

    0 讨论(0)
  • 2020-12-14 06:10

    According to this RFC:

    Content lines are delimited by a line break, which is a CRLF sequence (CR character followed by LF character).

    So you should use \r\n. I used this in strings without additional backslash escaping.

    0 讨论(0)
  • 2020-12-14 06:25

    Your output file should be like below---

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//2013//#Ur Site Name#//EN
    BEGIN:VEVENT
    UID:[event]2012
    DTSTART:20130101T100000
    DTEND:20130101T120000
    LOCATION:
    SUMMARY:#Meeting Title here#
    DESCRIPTION:What is realistic for financial services companies to achieve via Social Media channels?    \n\nJoin us on 11th September 2013 at 4pm (BST) where we 
    -----bla bla bla ----
    END:VEVENT
    END:VCALENDAR
    

    Here you have to take care of Version, it should be 2.0 and Escape char ... \n(newline), semicolon(;) and comma(,). If you are writing in .net then it should like ... "\\n", "\\;" and "\\,".

    You can check your output file on this site as well... https://icalendar.org/validator.html

    Thanks, Bhaskar

    0 讨论(0)
  • 2020-12-14 06:28

    OK, looks like I'm answering my own question.

    The correct way to do it is to use "\n" for line breaks. Outlook did not recognize this because I had "ENCODING=quoted-printable" on the description. Once I removed that, Outlook displayed the new lines correctly.

    Also, to get the file to open correctly in Apple iCal, you need to use "VERSION:2.0" for the file version. If you use "VERSION:1.0", it will tell you it can't read the file (even though it conforms to the 1.0 spec).

    NOTE: As others have mentioned, the file actually has to contain the literal string \n. Since most languages treat that as an escape sequence meaning a newline character, you probably need to use the string \\n in your code.

    0 讨论(0)
提交回复
热议问题