使用Google日历API(PHP)插入包含非ASCII字符的事件
我在使用谷歌日历API(PHP)的v3插入事件时遇到问题 如果某个事件的描述包含英镑符号等字符,则会在日历中创建该事件,但描述保留为空。这似乎适用于初始7位字符代码(ASCII代码0-127)之外的所有字符 通过使用htmlentities函数,我可以将井号的所有实例替换为:使用Google日历API(PHP)插入包含非ASCII字符的事件,php,encoding,calendar,ascii,google-calendar-api,Php,Encoding,Calendar,Ascii,Google Calendar Api,我在使用谷歌日历API(PHP)的v3插入事件时遇到问题 如果某个事件的描述包含英镑符号等字符,则会在日历中创建该事件,但描述保留为空。这似乎适用于初始7位字符代码(ASCII代码0-127)之外的所有字符 通过使用htmlentities函数,我可以将井号的所有实例替换为:£ 如果用户使用的是基于网络的谷歌日历,但移动应用程序不会将其转换回英镑符号,则这是可以接受的 这是一个相当大的问题,因为事件通常是从使用非ascii引号的Microsoft Word复制/粘贴的 有没有某种编码方
£代码>
如果用户使用的是基于网络的谷歌日历,但移动应用程序不会将其转换回英镑符号,则这是可以接受的
这是一个相当大的问题,因为事件通常是从使用非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);
此代码将插入事件:
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。事实证明有一个简单的解决方案。我将HTTP头设置为使用utf-8字符集,但没有专门编码我的描述。要将我的描述添加到我现在使用的事件中,请执行以下操作:
$event->setDescription(utf8_encode($description));
为什么在htmlentities函数中使用“cp1252”?这是针对我在别处发现的类似问题提出的,但没有解决问题。我最初使用“utf-8”作为参数。您是否可以粘贴插入请求的http请求的转储。