Question

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:7a6db67f3edff4729956c47ec@calendarlabs.com
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?

Was it helpful?

Solution

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;
    

OTHER TIPS

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/.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top