Jump to content

Recommended Posts

Posted

Hi there.

 

I have the need to be able to create an rss feed fed from a shared calendar. I found a bit of php that apparently does the job but Im some what at a loss as to how to get it working. Its called ical2rss and is widely available if you search.

 

Lets say I cant get that to work for whatever reason, is there something out there that will allow me to import an .ics calendar and be able to make an rss feed from it.

 

I can find everything under the sun about doing the other way round but I not this way.

 

Any one got any ideas as to how i can go forward with this?

 

Apologies if its in the wrong place.

  • 7 years later...
Posted (edited)

I found it actually easier to use a little PHP function to sort the ical into an array, luckily the structure is pretty easy to parse.

 

function icsToArray($paramUrl) {    
      $icsFile = file_get_contents($paramUrl);    
      $icsData = explode("BEGIN:", $icsFile);    
      foreach($icsData as $key => $value) {        
             $icsDatesMeta[$key] = explode("\n", $value);   
}   
foreach($icsDatesMeta as $key => $value) {
       foreach($value as $subKey => $subValue) {
       if ($subValue != "") {
           if ($key != 0 && $subKey == 0) {
           $icsDates[$key]["BEGIN"] = $subValue;
           } else {
           $subValueArr = explode(":", $subValue, 2);
           $icsDates[$key][$subValueArr[0]] = $subValueArr[1];
           }
       }
       }
   }
   return $icsDates;
   }

 

And then to show the latest 5 events with a summary

$events = icsToArray('calendar/1.ics');
//$events = icsToArray("https://outlook.office365.com/owa/calendar/youroffice365livelinkhere/reachcalendar.ics");                                    
$counter = 0;                   
// Loop through 5 events                    
foreach($events as $event){                                                
// Check the event summary is not null and display                       
if ($event['SUMMARY'] != '') {                           
// Define the strings                            
$date = NULL;                           
$summary = NULL;                            
$date = $event['DTSTART;VALUE=DATE'];                            
$date = substr_replace($date, '-', 4, 0);                            
$date = substr_replace($date, '-', 7, 0);                           
$summary = $newstr = str_replace('\\','', $event['SUMMARY']);                                                        
// Display each events                            
echo "";                           
echo "
";                                                        
echo "".$date."";                            
echo "

";                            
echo $summary."";                                                        
// Count up each time we find a valid event                           
$counter++;                        
}                        
// Break out of the loop if we have more than 5 events                       
if ($counter > 5) {                           
Break;                       
}                    
}

Edited by supportman

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...