I’m trying to debug an emergency alert script. It should be checking to see if the XML item is less than ‘40000000000’ seconds old and echo ‘Its been less than 24 hours’. I set it to a crazy high number and it’s still returning "else".
<?php
$xml=simplexml_load_file("https://content.getrave.com/rss/harpercollege/channel1");
foreach($xml->channel->item as $child)
{
unset($titleVal, $descriptionVal, $pubdate, $dateString);
$titleVal = (string)$child->title;
$descriptionVal = (string)$child->description;
$pubDate = (string)$child->pubDate;
$pubDate= date("D, d M Y H:i:s T", strtotime($pubDate));
echo $titleVal . "<br>" . $descriptionVal . "<br>" . $pubDate . "<br>";
if($pubDate > time() + 40000000000) {
echo 'Its been less than 24 hours';
} else {
echo '24 Hours have passed';
}
}
?>
2
Answers
The file you are using has a
<pubDate>Fri, 29 Oct 2021 13:25:47 GMT</pubDate>
So, for testing purposes fake a sensible date so you know what should be happening, then you dont have to change the code to do riduculous things and you are actually testing in a real situation and wont have to amend the code to work properly with real data! Never a good idea!!!Try using this
but i still didn’t understand your need
EDIT;
Date from xml we get is Fri, 29 Oct 2021 13:25:47 GMT which is about a year old
Try using new date which is less then a day old
for example if we suppose
$pubDate is Wed, 18 Oct 2022 04:12:00 GMT