在PHP开放时间 [英] Opening hours in PHP

查看:95
本文介绍了在PHP开放时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户想要一个在线比萨店,而且他也不希望客户在开放时间之后下订单 - 当然。我做了一个简单的脚本,我以为我可能会和任何想要在未来的人分享。

解决方案

 <?php 
date_default_timezone_set('Europe / Stockholm'); // timezone

$ weekday = date(l); // today
// print $ weekday; // Debug
// print date(H:i); // debug

//设置一周中每一天的开放和关闭时间
if($ weekday ==Friday){
$ open_from =11:00 ;
$ opten_to =21:45;
}
elseif($ weekday ==Saturday|| $ weekday ==Sunday){
$ open_from =12:00;
$ open_to =21:45;
}
else {
$ open_from =11:00;
$ open_to =20:45;
}

//现在检查当前时间是否在开放时间之前或之后
if(date(H:i)< $ open_from || date( H:i)> $ open_to){
打印已关闭!;
}

//显示结帐按钮
else {
打印打开!
}
?>


I had a client that wanted an online pizza shop, and he also didn't want customers to place orders after opening hours - of course. I made just a little simple script for that, that I thought I might share with anyone who wants that in the future.

解决方案

<?php
    date_default_timezone_set('Europe/Stockholm'); // timezone 

    $weekday = date(l); // today
    //print $weekday; // Debug
    //print date("H:i"); // debug

    // Set open and closing time for each day of the week
    if ($weekday == "Friday") {
        $open_from = "11:00";
        $opten_to = "21:45";
    }
    elseif ($weekday == "Saturday" || $weekday == "Sunday") {
        $open_from = "12:00";
        $open_to = "21:45";
    }
    else {
        $open_from = "11:00";
        $open_to = "20:45";
    }

    // now check if the current time is before or after opening hours
    if (date("H:i") < $open_from || date("H:i") > $open_to ) {
        print "Closed!";
    }

    // show the checkout button
    else {
        print "Open!";
    }
?>

这篇关于在PHP开放时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆