I am currently working with jQuery FullCalendar plugin and I just made a function which exports my events into a Google Calendar format. The problem I encounter is that when I download it, I have two extra spaces at the beginning of the file. Unfortunatly, the import fails due to these spaces.
Here's how I create the file and generate the download :
$ical = "BEGIN:VCALENDAR
VERSION:2.0";
foreach($events as $e){
$ical .= "\nBEGIN:VEVENT
UID:" . md5(uniqid(mt_rand(), true)) . "@example.test
DTSTAMP:" . gmdate('Ymd').'T'. gmdate('His') . "Z
DTSTART: ". $this->formatDate($e['E_dateStart']) ."
DTEND:". $this->formatDate($e['E_dateEnd']) ."
SUMMARY:". $e['E_description'] ."
END:VEVENT";
}
$ical .= "\nEND:VCALENDAR";
$ical = str_replace("\t", "", $ical);
$ical = str_replace(" ", "", $ical);
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=calendar.ics');
echo "$ical";
exit;
And then the downloaded file looks like this :
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:3a24a50a6b9af94c0665c6528f9e38aa@example.test
DTSTAMP:20150330T083230Z
DTSTART:20150329T000000Z
DTEND:20150327T001200Z
SUMMARY:test
END:VEVENT
END:VCALENDAR
I have two spaces just before BEGIN VCALENDAR and I can't figure out where it comes from. I'm guessing it is caused by PHP echo but I'm not sure and I don't know how I could do it differently.