PHP代码构成动态倒数计时器
有时,我们需要在网站上宣布某些内容或希望对读者有任何喜庆,然后我们需要一种计时器(可以说是倒数计时器)显示在网站上。
在本文中,我们正在编写PHP代码,该代码将在网页上显示“排灯节”的倒数计时器。
在这段代码中
我们正在使用一个函数strtotime(),该函数用于人为生成选定日期和时间的时间戳。
我们正在定义节日“排灯节”的日期和时间,也就是目标日期时间,其值为“2017-10-1912:00:00”。
并且,作为当前日期时间,我们现在使用它来给出当前日期和时间。
PHP代码(带有HTML)显示倒数计时器
<!doctype html>
<html>
<head>
<title>PHP Countdown Timer</title>
</head>
<body>
<?php
$diwali = strtotime("2017-10-19 12:00:00"); //或排灯节是
$current=strtotime('now');
$diffference =($diwali-$current);
$days=floor($diffference / (60*60*24));
echo "$days days left on Diwali";
?>
</br>
<?php
$image_url='http://happydiwali2016imageshd.in/wp-content/uploads/2017/09/Diwali-GIF-1.gif';
?>
<img src="<?php echo $image_url;?>">
</body>
</html>输出结果