Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Help with CRLF text output please

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
JPLiggett
Smarty n00b


Joined: 05 Oct 2017
Posts: 2

PostPosted: Thu Oct 05, 2017 10:35 pm    Post subject: Help with CRLF text output please Reply with quote

This tpl code writes out a vcalendar ics file, which is missing the CRLF on line 1 in the output file. How can I add the \n\r or " in the template for the CRLF?

BEGIN:VCALENDAR<need CRLF here>
VERSION:2.0
METHOD:REQUEST
PRODID:-//BookedScheduler//NONSGML {$bookedVersion}//EN
{foreach from=$Reservations item=reservation}
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:{formatdate date=$reservation->DateCreated key=ical}
DESCRIPTION:{$reservation->Description|regex_replace:"/\r\n|\n|\r/m":"\n "}
DTSTAMP:{formatdate date=$reservation->DateCreated key=ical}
DTSTART:{formatdate date=$reservation->DateStart key=ical}
DTEND:{formatdate date=$reservation->DateEnd key=ical}
LAST-MODIFIED:{formatdate date=$reservation->LastModified key=ical}
LOCATION:{$reservation->Location}
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Thu Oct 05, 2017 11:36 pm    Post subject: Reply with quote

You say you are losing the actual newline character between the first and second lines? Interesting. But none of the others?

I haven't tried this, but since Smarty can use many PHP functions without prior setup, try:
Code:
BEGIN:VCALENDAR{chr(13)}{chr(10)}
VERSION:2.0
Back to top
View user's profile Send private message
JPLiggett
Smarty n00b


Joined: 05 Oct 2017
Posts: 2

PostPosted: Fri Oct 06, 2017 3:51 am    Post subject: Thank you- this helped alot Reply with quote

but the first line now has the CRLF and the validator complains that the CRLF is missing.

BEGIN:VCALENDAR{chr(13)}
VERSION:2.0 {chr(13)}
METHOD:REQUEST {chr(13)}
PRODID:-//BookedScheduler//NONSGML {$bookedVersion}//EN {chr(13)}
{foreach from=$Reservations item=reservation}
BEGIN:VEVENT{chr(13)}
CLASS:PUBLIC {chr(13)}
CREATED:{formatdate date=$reservation->DateCreated key=ical} {chr(13)}
DESCRIPTION:{$reservation->Description|regex_replace:"/\r\n|\n|\r/m":"\n "}
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Oct 06, 2017 6:47 am    Post subject: Reply with quote

Some specifications want:
CRLF: two bytes - chr(13)chr(10) - Windows DOS
CR only: Macintosh
LF only: Unix and others

A sloppily expressed error message could say CRLF instead of "newline appropriate for your operating system".

A strict, accurate error message, if it says CRLF is missing, then only adding the CR part is still wanting the LF part.

Or, it could be the case that your text editor is using LF as the newline, and so adding just {chr(13)} might be what you are trying to do.

I would use a programmer's text editor that can view the rendered output from after Smarty processing this template as a hex dump. Make sure there is only 0D 0A as newlines.

A programmer's text editor should be able to load a document and not auto-convert newlines to the system's default bytes. Or be able to save the document using specified newlines regardless of the system.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Oct 06, 2017 5:44 pm    Post subject: Re: Help with CRLF text output please Reply with quote

JPLiggett wrote:
This tpl code writes out a vcalendar ics file, which is missing the CRLF on line 1 in the output file. How can I add the \n\r or " in the template for the CRLF?

BEGIN:VCALENDAR<need CRLF here>

Then save your template with CRLF EOL marks.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Oct 06, 2017 5:50 pm    Post subject: Reply with quote

bsmither wrote:
A sloppily expressed error message could say CRLF instead of "newline appropriate for your operating system".

IIRC, VCard format explicitly requires \r\n.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP