使用php的domdocument从Google日历获取信息 [英] Getting information from Google Calendar using php's domdocument
本文介绍了使用php的domdocument从Google日历获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是代码。似乎根本没有打开Google日历。我相信这与我正在使用的网址有关,并且可能与特殊字符有关。我得到以下信息:
Below is the code. It seems to not be opening the google calendar at all. I believe it has something to do with the url I am using and possbily the special character. I get the following:
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/public/basic" on line 4
<?
$dom = new DOMDocument();
$feed = "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/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";
}
}
?>
推荐答案
据我所知, DOMDocument :: loadHTMLFile()
可以协商SSL,但是如果失败,则可以尝试 file_get_contents()
首先将文件读入
As far as I know, DOMDocument::loadHTMLFile()
is capable of negotiating SSL, but if it is failing you might try file_get_contents()
to read the file first into a string.
$dom = new DOMDocument();
$feed = "https://www.google.com/calendar/feeds/tjd@dreilinginc.com/public/basic";
$feed_string = file_get_contents($feed);
$html = $dom->loadHTMLFile($feed_string);
这是完全投机的。
编辑,请确保在您的PHP中启用了 allow_url_fopen
.ini。
EDIT Make sure that allow_url_fopen
is enabled in your php.ini.
这篇关于使用php的domdocument从Google日历获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文