0
以下是代碼。它似乎根本不打開谷歌日曆。我相信這跟我使用的url有關,並且可能是特殊字符。我得到如下:使用php的domdocument從Google日曆獲取信息
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity "https://www.google.com/calendar/feeds/[email protected]/public/basic" on line 4
<?
$dom = new DOMDocument();
$feed = "https://www.google.com/calendar/feeds/[email protected]/public/basic";
$html = $dom->loadHTMLFile($feed);
$dom->preserveWhiteSpace = true;
$entries = $dom->getElementsByTagName("entry");
foreach ($entries as $entry)
{
$status = $entry->getElementsByTagName("eventStatus");
$eventStatus = $status->item(0)->getAttributeNode("value")->value;
if ($eventStatus == $confirmed)
{
$titles = $entry->getElementsByTagName("title");
$title = $titles->item(0)->nodeValue;
$times = $entry->getElementsByTagName("when");
$startTime = $times->item(0)->getAttributeNode("startTime")->value;
$when = date("l jS \o\f F Y - h:i A", strtotime($startTime));
$places = $entry->getElementsByTagName("where");
$where = $places->item(0)->getAttributeNode("valueString")->value;
print $title . "\n";
print $when . " AST\n";
print $where . "\n";
print "\n";
}
}
?>
警告:file_get_contents(https://[email protected]/public/basic)[function.file-get-contents]:未能打開流:在/ home/timeline/public_html中沒有這樣的文件或目錄第4行的/getEventsFromCalendar.php當我執行您的建議更改時,我會獲得此信息。 –
@joe休斯我沒有這個問題。我可以用'file_get_contents()'讀取URL,以便您可能遇到網絡問題,或者PHP無法連接到網絡。 –
@joe Hughes確保'allow_url_fopen'在php.ini中打開 –