No linebreaks in vcalendar file when echoing values with PHP

374 views Asked by At

I have a vcalendar file. It works perfect if i type it between php tags like this

?>


BEGIN:VEVENT
DTSTART;VALUE=DATE:20110422
DTEND;VALUE=DATE:20120529
DTSTAMP:20120529T124028Z
UID:[email protected]
CREATED:20111213T123901Z
DESCRIPTION:Visit http://www.calendarlabs.com/holidays/ to know more about New Year's Day and for any other calendar needs.
LAST-MODIFIED:20111213T123901Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:New Year's Day
TRANSP:TRANSPARENT
END:VEVENT


 <?php

 echo :

However, soon as i put it in echo statements like so:

 echo "BEGIN:VEVENT"; 

then it doesn't work. I have tried adding \n,
everything.

Also doesnt work if i do something like:

   DTSTART;VALUE=DATE:<?php echo $date; ?>

Can anybody else see a solution here?

2

There are 2 answers

0
AudioBubble On BEST ANSWER

PHP's closing tag eats whitespace following it. If you want to preserve newlines when outputting with PHP, you will need to do one of the following:

  • Output the newline character explicitly:

    DTSTART;VALUE=DATE:<?php echo $date, PHP_EOL; ?>
    
  • Use heredoc syntax:

    echo <<<END
    BEGIN:VEVENT
    ...
    DTSTART;VALUE=DATE:$date
    END;
    
0
J A On

Your web server probably does not recognize .ics file as a script, therefore it does not send the file to the hypertext processor (php) to process the instructions inside php tags. You need to tell your web server to treat this as a php file. Tutorial for adding custom extension could be found here: http://creativebriefing.com/custom-file-extensions/.