Skip to content

Instantly share code, notes, and snippets.

@nickrussler
Last active May 13, 2016 13:34
Show Gist options
  • Save nickrussler/93717238f63a5b3bcb58568bd864a6bf to your computer and use it in GitHub Desktop.
Save nickrussler/93717238f63a5b3bcb58568bd864a6bf to your computer and use it in GitHub Desktop.
Snippet to filter AirBnB Not available events and fix the end date
<?php
$ch = curl_init("https://www.airbnb.de/calendar/ical/XYZ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
$state = 0;
$result = "";
$temp = "";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $data) as $line){
if (strcmp("BEGIN:VEVENT", $line) == 0) {
$state = 1;
}
if (strcmp("SUMMARY:Not available", $line) == 0) {
$state = 2;
}
if ($state == 0) {
$result .= $line . "\n";
} else {
$DTENSTR = "DTEND;VALUE=DATE:";
$datepos = strpos($line, $DTENSTR);
if ($datepos !== false) {
$temp = $temp . "\n" . $DTENSTR . date("Ymd", strtotime("+1 day", strtotime(substr($line, strlen($DTENSTR)))));
} else {
$temp = $temp . "\n" . $line;
}
}
if (strcmp("END:VEVENT", $line) == 0) {
if ($state == 1) {
$result .= trim($temp) . "\n";
$temp = "";
}
$state = 0;
}
}
echo trim($result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment