2011-10-20 258 views
4

我試圖從我的web應用程序插入谷歌日曆中的事件描述,我不能\ n或<br />被解釋爲換行符。 Google日曆如何解釋換行符?幫助將不勝感激!Google Calendar API的換行符?

回答

-1

「/ n」僅適用於iCal條目。使用Google Calendar API,您不能執行換行。

+0

所以它不可能有事件描述的換行符...? – Ben

+0

通過Google API,是的。通過iCal界面,您可以使用「\ n」 –

+2

我確信在問題提出後的過去3年中發生了一些變化,但您現在可以做到這一點。你只需要爲JSON格式化你的字符串。 「\ n」變成「\\ n」。這是一個有用的C#函數來做到這一點: http://stackoverflow.com/questions/1242118/how-to-escape-json-string/21455488#21455488 – Vandel212

0

我不確定谷歌日曆是如何解釋新行,但似乎每行有121個字符。

所以說,你想把「地址:」/ n的細節谷歌日曆。
以121減去「地址:」的字符數並將113個空格添加到「地址:」

以下文本應在新行上。

如果您發送的文本是一個PHP變量,在PHP中創建新行更容易。

$description = 'Description:'.'\n'; 

然後谷歌日曆將它作爲一個新行讀取它。

1

您是否使用特定的客戶端庫?如果使用的協議,簡單地將新行的內容元素應該工作:

<?xml version="1.0" encoding="UTF-8"?> 
<entry xmlns="http://www.w3.org/2005/Atom" 
     xmlns:gCal="http://schemas.google.com/gCal/2005" 
     xmlns:gd="http://schemas.google.com/g/2005"> 
    <title type="text">Event with new line</title> 
    <content type="text">This is an event with one 
two 
three 
and and four lines.</content> 
<gd:when endTime="2011-12-23T10:00:00.000-07:00" 
     startTime="2011-12-23T08:00:00.000-07:00"/> 
</entry> 

如果使用客戶端庫,使用「\ n」應該正常工作。

1

Heredocs是我如何運作的。

$content = <<<EOT 
This 
is 
my 
content 
EOT; 

您不能定界符的內部循環,但你可以建立起來,像這樣

$content = ''; 
for ($vars as $var) { 
$content .= <<<EOT 
$var 

EOT; 
} 
1

使用API​​ V3,這個工作對我來說:

$full_description .= 'Evento organizado por: ' . $area_responsavel . "\n\n"; $full_description .= $mensagem;

+1

單個「\ n」爲我工作。雖然使用雙引號很重要! (單引號不起作用) – tiho

1

用這個在google日曆事件描述中創建一個換行符:

\\n 

蘭德爾麥格林寫在註釋中正確答案:

我敢肯定,一些在過去3年中已經改變,因爲這個問題被問,但你現在可以做到這一點。你只需要爲JSON格式化你的字符串。 「\ n」變成「\ n」。