poniższy kod zamienia plik .csv do .ics (kalendarz). w przetwarzanym pliku csv są różne pola np.nr telefonu, uwagi. jak pobrać konkretne pole (kolumnę), żeby utworzyć dla niej np:
SUMMARY: Imię i Nazwisko
DESCRIPTION: uwagi\nTel: xxx-xxx-xxx
<?php
$fp = fopen("calendar.csv", 'r');
$i = 0;
if ($fp){
if (flock($fp, LOCK_SH
)){
# $line = mb_convert_encoding($line, 'auto', 'auto');
if($i == 0){
// header of csv file
$header = $line;
}else{
$data[] = $line;
}
$i++;
}
}
}
#unlink($filepath);
$header_item = explode(",", $header);
// designate file path
$file_name = "calendar.ics";
// open file
$fp = fopen($file_name, 'w');
// number of data
$i = $i - 2;
//X-WR-TIMEZONE:Europe/Warsaw
// write header part
$common = "BEGIN:VCALENDAR" . "\n";
$common = "VERSION:2.0" . "\n";
$common = "PRODID:-//Google Inc//Google Calendar 70.9054//EN" . "\n";
$common = "CALSCALE:GREGORIAN" . "\n";
$common = "METHOD: PUBLISH" . "\n";
$common = "X-WR-CALNAME:Pacjenci PŁ" . "\n";
$common = "X-WR-TIMEZONE:Europe/Warsaw" . "\n";
// write data
for($count = 0; $count < $i; $count++){
$common = "BEGIN:VEVENT" . "\n";
for($j = 0; $j < count($header_item); $j++){ $data_item = explode(",", $data[$count]); $item = $header_item[$j] . ":" . $data_item[$j] . "\n";
}
$common = "END:VEVENT" . "\n";
}
// write footer part
$common = "END:VCALENDAR" . "\n";
// download ics file
$fname = "calendar.ics";
#header('Content-Type: application/force-download');
# header('Content-Length: ' . filesize($file_name));
#header('Content-disposition: attachment; filename="' . $fname . '"');
// delete file
#unlink($file_name);
?>
Ten post edytował dentopolis 30.12.2021, 00:38:06