gpt4 book ai didi

syntax-error - 此 iCalendar 事件代码中是否存在语法错误?

转载 作者:行者123 更新时间:2023-12-03 08:28:00 24 4
gpt4 key购买 nike

我的 iPhone 上有一个“订阅日历”,它从 URL 获取 iCalendar 格式的日历事件。日历工作正常,只是它不显示以下事件,有什么原因吗?所有其他事件都显示正常。我认为事件的格式化/语法方式可能存在问题,但我似乎找不到任何可能导致它的东西。

BEGIN:VEVENT SUMMARY:Meet with tenant DESCRIPTION:Notes: Meter readings\, SoC images\, post box key\, finalise Let Procedure.\nLocation: Apartment X X Woodland Road\, Bebington\, Wirral\, CHXX XXX\nEmployee: Michael Le Brocq\nStatus: Confirmed\nOriginally Arranged: 07/09/16 12:18:43 by Lucy Christian\nLast Updated: 12/09/16 15:57:05 by Michael Le Brocq\n UID:2432 STATUS:CONFIRMED DTSTART:20160914T160000 DTEND:20160914T151500 LAST-MODIFIED:20160912T155705 LOCATION:Apartment 5 20 Woodland Road\, Bebington\, Wirral\, CH42 4NT END:VEVENT

用于生成日历事件的代码;
<?php

require_once('../inc/app_top_cron.php');

if (!empty($_GET)) {

// define and escape each GET as a variable

foreach ($_GET as $key => $value) {

if (!empty($value)) {

${$key} = mysqli_real_escape_string($con, PrepareInput($value));

}
}
}

// company details
$company_details_query = mysqli_query($con, "SELECT company_id, company_trading_name FROM company WHERE company_token = '" . $company . "' LIMIT 1") or die(mysql_error());
$company_details = mysqli_fetch_array( $company_details_query );

// the iCal date format. Note the Z on the end indicates a UTC timestamp.
define('DATE_ICAL', 'Ymd\THis');

// max line length is 75 chars. New line is \\r\n

$output = "BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Property Software//Calendar//EN
CALSCALE:GREGORIAN
X-WR-CALNAME:" . $company_details['company_trading_name'] . " Calendar" . "
\r\n";

$sql = "SELECT ce.*, ces.calendar_event_status_name
FROM calendar_event ce
INNER JOIN calendar_event_status ces
on ce.calendar_event_status = ces.calendar_event_status_id
WHERE ce.calendar_event_company_id = '" . $company_details['company_id'] . "'";

$calendar_event_query = mysqli_query($con, $sql) or die(mysql_error());

while($row = mysqli_fetch_array( $calendar_event_query )) {

$calendar_event_subject = str_replace(",","\,", $row['calendar_event_subject']);

$calendar_event_description = str_replace(",","\,", $row['calendar_event_description']);
$calendar_event_description = str_replace("\r\n","\\n", $calendar_event_description);

$calendar_event_location = str_replace(",","\,", $row['calendar_event_location']);

// loop through events
$output .=
"BEGIN:VEVENT
SUMMARY:" . $calendar_event_subject . "
DESCRIPTION:" . $calendar_event_description . "
UID:" . $row["calendar_event_id"] . "
STATUS:" . $row["calendar_event_status_name"] . "
DTSTART:" . date(DATE_ICAL, strtotime($row["calendar_event_start"])) . "
DTEND:" . date(DATE_ICAL, strtotime($row["calendar_event_end"])) . "
LAST-MODIFIED:" . date(DATE_ICAL, strtotime($row["calendar_event_date_updated"])) . "
LOCATION:" . $calendar_event_location . "
END:VEVENT
";
}

// close calendar
$output .= "END:VCALENDAR";

echo $output;

mysqli_close($con);

?>

最佳答案

这:

$calendar_event_description = str_replace("\r\n","\\n", $calendar_event_description);

你正在服用 \r\n (回车 + 换行)并将它们变成文字 \字符,后跟 n .这不是一个新行(一个字节/字符),它是两个字节/字符,并且对任何东西都没有特殊含义。

根据我上面的评论,不要进行多行字符串构建/连接。它导致难以阅读和难以理解的调试。使用 heredoc反而:
$output = <<<EOL
BEGIN:VEVENT
SUMMARY: {$calendar_event_subject}
DESCRIPTION: {$calendar_event_description}
UID: {$row["calendar_event_id"]}
etc...
EOL;

请注意缺少任何 ". - 制作更紧凑且易于遵循的代码块。如果您之后需要更改换行符,因为您的系统使用的内容与您的代码编辑器嵌入的内容不同,您可以在完成构建字符串后使用简单的 str_replace() 来完成。

关于syntax-error - 此 iCalendar 事件代码中是否存在语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39479065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com