I am very new to php so i have been trying to make a basic simple application that reads the json file and fetches that data into your application from that file. i am trying to build some logic that it fetches the data of some specific dates i.e data of within 72 hours. Date is given in the file in "1/12/2020" format. i was trying to convert the json date in seconds and subtracting it with system date(in seconds) and then comparing that difference date(system date - date data given in json file) with 72 hours (in seconds). but i couldn't do so. here's what i have tried
<?php
$str_data = file_get_contents("json_response.json");
$data = json_decode($str_data, true);
echo "<div class='container-fluid'>
<ul class='w3-ul w3-card-4'>";
for($i = 0; $i < sizeof($data["Messages"]); $i++) {
$id=$data["Messages"][$i]["id"];
$pnum=$data["Messages"][$i]["phonenumber"];
$body=$data["Messages"][$i]["body"];
$m_date=$data["Messages"][$i]["M_date"];
$is_read=$data["Messages"][$i]["isRead"];
$M_date_inSecs = strtotime($m_date);
$system_date_inSecs = strtotime("now") ;
$difference_time = $system_date_inSecs - $M_date_inSecs;
if($is_read=="false" && $difference_time <= strtotime("72 hours") )
echo "
<li class='w3-bar'>
<span onclick='this.parentElement.style.display=\"none\"'class='w3-bar-item w3-button w3-white w3-large w3-right'>×</span>
<table class='float-right text-secondary'>
<tr><td>$m_date</td></tr>
<tr><td>Read Status: $is_read</td></tr>
</table>
<img src='profile.png' class='w3-bar-item w3-circle w3-hide-small' style='width:75px'>
<div class='w3-bar-item'>
<span class='w3-large'>{$id}:{$pnum} </span><br>
<span style='max-height:60px;overflow:auto;max-width:800px;display:block;'>$body</span>
</div>
</li>";
}
echo "</ul></div>";
?>
here's the sample json data
"Messages":[
{
"id":"0",
"phonenumber":"Sannan ITU",
"body":"Manan jaldi aja lecture bhi hai is ka 1:45",
"M_date":"31/7/2020",
"isRead":"false"
},
]
}
so where's i am doing wrong. Any suggestion would be really appreciated.
$data["Messages"]Please make your data sample make sence