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';
}
}
?>
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!!!
$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));
### Uncomment one or the other of these KNOWN dates
# fake a sensible date time less than 24 hours old
#$pubDate= 'Wed, 19 Oct 2022 13:25:47 GMT';
# fake a sensible date time GRETAER than 24 hours old
$pubDate= 'Tue, 18 Oct 2022 13:25:47 GMT';
#convert it to a timestamp (compare apples and apples and not apples and oranges)
$pubDate = strtotime($pubDate);
# Test the pubDate against NOW, time() MINUS 1 day (24*60*60)
# Test the pub date is Greater that now minus a days worth of seconds
if($pubDate > time() - 24*60*60) {
echo 'Its been less than 24 hours';
} else {
echo '24 Hours have passed';
}
}
Try using this
<?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';
}
}
?>
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
.......
$pubDate= date("D, d M Y H:i:s T", strtotime($pubDate));
$pubDate = 'Wed, 18 Oct 2022 04:12:00 GMT';
echo $titleVal . "<br>" . $descriptionVal . "<br>" . $pubDate . "<br>";
if($pubDate < time() + 86400) {
echo 'Its been less than 24 hours';
} else {
echo '24 Hours have passed'. $timepls;
}
}
?>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.