我在使用 Google Calendar API (PHP) v3 插入事件时遇到问题。
如果事件的说明包含井号 £ 等字符,则会在日历中创建该事件,但说明留空。似乎对于初始 7 位字符代码(ASCII 代码 0-127)之外的所有字符都是如此。
通过使用 htmlentities 函数,我可以将井号的所有实例替换为:£
如果用户使用基于网络的 Google 日历版本,但移动应用程序不会将其转换回井号,则这很好。
这是一个相当大的问题,因为事件通常是从使用非 ASCII 引号的 Microsoft Word 复制/粘贴的。
是否有某种编码方法可以解决这个问题?我目前在 MySQL 数据库和 PHP 脚本中使用 UTF-8 编码。
我使用以下代码来创建事件:
function buildGoogleEvent($title,$description,$start_time,$end_time,$location) {
// Create an event object and set some basic event information
$event = new Google_Event();
$event->setSummary($title);
$event->setLocation($location);
$event->setDescription(htmlentities($description, ENT_NOQUOTES, 'utf-8'));
// Convert the start and end date/times to ATOM format
$start_time_atom = str_replace(" ", "T", $start_time);
$end_time_atom = str_replace(" ", "T", $end_time);
// Add the event start to the event object
$start = new Google_EventDateTime();
$start->setDateTime($start_time_atom);
$start->setTimeZone('Europe/London');
$event->setStart($start);
// Add the event end to the event object
$end = new Google_EventDateTime();
$end->setDateTime($end_time_atom);
$end->setTimeZone('Europe/London');
$event->setEnd($end);
return $event;
}
此代码插入事件:
$createdEvent = $service->events->insert($google_calendar_id, $event);
已经坐了很长一段时间了,所以非常感谢任何帮助!我的PHP版本是5.5.4。