I am getting an error while trying to extract some data from Google Cal using PHP. Here is the code:
$url = $_POST['url'];
$xml = file_get_contents($url);
$feed = simplexml_load_string($xml);
$ns= $feed->getNameSpaces(true);
foreach ($feed->entry as $entry) {
$eventdetail = $entry->children($ns["gd"]);
$when_atr = $eventdetail->when[0]->attributes();
$title = $entry->title;
echo "<div class='eventTitle'>".$title . "</div>";
$where = $eventdetail->where[0]->attributes();
echo "<div class='eventLocation'>" . $where . "</div>" . '<br />';
$start = new DateTime($when_atr['startTime']);
echo "<div class='eventTime'>".$start->format('D F jS, g:ia') . " to ";
$end = new DateTime($when_atr['endTime']);
echo $end->format('g:ia')."</div>" . '<br />' ;
}
The headers work fine, but for "when" and "where" I have problems with the code when[0]->attributes();and where[0]->attributes();.
The error I get is
Fatal error: call member function () attributes on non-object
What can I do to prevent this from happening?
jahed source
share