我按照教程使用PHP将iCal数据导入我的网站。出于某种原因,即使Feed在Feed验证器网站中显示信息,该阵列似乎也不包含任何数据。任何人都可以看看解码器功能?我猜这有一个简单的原因,但我是新手。
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;
}
答案 0 :(得分: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;
}