/i', "\n\n", $str); $str = preg_replace('/\/i', "\n", $str); $str = strip_tags($str); $str = trim(html_entity_decode($str, ENT_QUOTES, 'UTF-8')); // no more than two newlines please $str = preg_replace("/(\r?\n){3,}/", "\n\n", $str); // lines can't be more than 75 chars, use 60 to be safe $lines = str_split($str, 60); foreach ($lines as $key => $line) { // escape special icalendar chars and convert newlines to '\n' $lines[$key] = str_replace(array('\\', ',', ';'), array('\\\\', '\,', '\;'), $lines[$key]); $lines[$key] = preg_replace("/\r?\n/", '\n', $lines[$key]); } return implode("\r\n ", $lines); } $location = <<