I use the following PHP to remove items from an XML I own if they are over 8 days old. It had worked fine once before but now gives me the error message
Call to a member function removeChild() on a non-object in /Users//DateTest-3.php on line 40
Line 40 is
$node->parentNode->removeChild($node); Any ideas why this is throwing the error?
<?php $rss = new DOMDocument(); $url = 'http://URL.com/Test.xml'; $rss->load($url); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('date')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 50; for ($i = 0; $i < count($feed); $i++) { date_default_timezone_set('America/Los_Angeles'); $newDate = strtotime("-8 day"); $date = strtotime($feed[$i]['date']); if ($date > $newDate) { echo "Don't delete"; } else { echo "Delete"; $node->parentNode->removeChild($node); } } $rss->save("Test.xml") ?>