0

I followed a tutorial to import iCal data into my website using PHP. For some reason, the array doesn't seem to include any data even though the feed shows info in a feed validator website. Can anyone take a look at the decoder function? I'm guessing there's a simple reason for this but I'm a novice.

    public function iCalDecoder($file) {
    $ical = file_get_contents('https://www.google.com/calendar/ical/689afn1fkt0cb59kame9bg56mg%40group.calendar.google.com/private-584915c30803f5ad6c548f021e84f836/basic.ics');
    preg_match_all('/(BEGIN:VEVENT.*?END:VEVENT)/si', $ical, $result, PREG_PATTERN_ORDER);
    for ($i = 0; $i < count($result[0]); $i++) {
        $tmpbyline = explode("rn", $result[0][$i]);

        foreach ($tmpbyline as $item) {
        $tmpholderarray = explode(":",$item);
        if (count($tmpholderarray) >1) {
            $majorarray[$tmpholderarray[0]] = $tmpholderarray[1];
        }
        }

        if (preg_match('/DESCRIPTION:(.*)END:VEVENT/si', $result[0][$i], $regs)) {
        $majorarray['DESCRIPTION'] = str_replace("  ", " ", str_replace("rn", "", $regs[1]));
        }
        $icalarray[] = $majorarray;
        unset($majorarray);

    }
    return $icalarray;

}
4

1 回答 1

0

找到了另一个实际有效的功能。感谢您的关注,我希望这对未来的人有所帮助!

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;
}
于 2013-04-24T01:52:37.617 回答