开发者

Getting information from Google Calendar using php's domdocument

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) 
 {
  开发者_JS百科      $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"; 
        }
    }
?>


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);

This is fully speculative though. Treat it as such.

EDIT Make sure that allow_url_fopen is enabled in your php.ini.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜