function get_xml_events($month, $year) { $events = array(); $xml = new SimpleXMLElement(iCalendarToXML()); foreach ($xml->VEVENT as $event) { //get start year,month,day and end year,month,day $start = date_parse_from_format("Ynj", (string) $event->DTSTART); $end = date_parse_from_format("Ynj", (string) $event->DTEND); //make timestamp for start, end, and current $end_of_month = gmmktime(0, 0, 0, $month + 1, 1, $year); $start_of_month = gmmktime(0, 0, 0, $month, 1, $year); $start_date = gmmktime(0, 0, 0, $start["month"], $start["day"], $start["year"]); $end_date = gmmktime(0, 0, 0, $end["month"], $end["day"], $end["year"]); //if current month and year are within start and end range if ($end_of_month > $start_date && $start_of_month < $end_date) { //if event start date is after first of month if ($start_of_month <= $start_date) { $total_days = floor(($end_date - $start_date) / 86400); //count and mark the booked days in the month for ($i = 0; $i <= $total_days && $i <= gmdate('t', $start_of_month); $i++) { $class = 'booked'; //special classes for first and last days if ($i == 0) { $class .= ' first'; } elseif ($i == $total_days) { $class .= ' last'; } $events[$start["day"] + $i] = $class; } } else { $total_days = floor(($end_date - $start_of_month) / 86400); for ($i = 0; $i <= $total_days && $i <= gmdate('t', $start_of_month); $i++) { $class = 'booked'; //special classes for last day if ($i == $total_days) { $class .= ' last'; } $events[$i + 1] = $class; } } } } return $events; }
$xml .= '<' . strtoupper($value) . ">\n"; $spaces += 2; continue; } elseif ($propertyName == 'END') { $spaces -= 2; $xml .= str_repeat(" ", $spaces); $xml .= '</' . strtoupper($value) . ">\n"; continue; } $xml .= str_repeat(" ", $spaces); $xml .= '<' . $propertyName; if ($attributes) { // There can be multiple attributes $attributes = explode(';', $attributes); foreach ($attributes as $att) { list($attName, $attValue) = explode('=', $att, 2); $xml .= ' ' . $attName . '="' . htmlspecialchars($attValue) . '"'; } } $xml .= '>' . htmlspecialchars($value) . '</' . $propertyName . ">\n"; } } return $xml; } // Input ical file to string $icalFile = 'https://www.google.com/calendar/ical/teamsiems%40gmail.com/public/basic.ics'; $icalString = file_get_contents($icalFile); $xmlString = iCalendarToXML($icalString); // Output xml string to file $xmlFile = 'google-ical.xml'; file_put_contents($xmlFile, $xmlString);