PHP存储时间,关闭日期 [英] PHP store hours, closed dates

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

问题描述

我已经下载了PHP商店的时间来显示工作日的开放时间,但是现在我想添加一些不同开放时间的特定日期(圣诞节快到!!-D),但我真的不知道如何这样做,所以我希望你的帮助。例如;我想改变25/12和1/1的开放时间,而不是所有的星期日。

I've downloaded PHP store hours to show the weekday's opening hours, but now I would like to add some specific dates with different opening hours ( soon christmas you know! :-D ) but I really don't know how to do that so I was hoping for your help. E.g; I would like to change the opening hours for 25/12 and 1/1 ONLY, not all sundays.

提前感谢!

// -------- PHP STORE HOURS ---------
// ---------- Version 1.1 -----------
// -------- BY CORY ETZKORN ---------
// -------- coryetzkorn.com ---------


// -------- EDIT FOLLOWING SECTION ONLY ---------

// Set your timezone (codes listed at http://php.net/manual/en/timezones.php)
// Delete the following line if you've already defined a timezone elsewhere.
date_default_timezone_set('Europe/Stockholm'); 

// Define daily open hours. Must be in 24-hour format, separated by dash.
$time_range_mon = '11:00-20:30';
$time_range_tue = '11:00-20:30';
$time_range_wed = '11:00-20:30';
$time_range_thu = '11:00-20:30';
$time_range_fri = '11:00-21:30';
$time_range_sat = '11:00-21:30';
$time_range_sun = '12:00-19:30';


// OPTIONAL: Output current day's open hours 
$echo_daily_hours = false; // Switch to FALSE to hide numerical display of current hours
$time_output = 'g a'; // Enter custom time output format (options listed here: http://php.net/manual/en/function.date.php)
$time_separator = ' - '; // Choose how to indicate range (i.e XX - XX, XX to XX, XX until XX)

// -------- END EDITING -------- 

// Gets current day of week
$status_today = date("D"); 

// Gets current time of day in 00:00 format
$current_time = date("G:i");
// Makes current time of day computer-readable
$current_time_x = strtotime($current_time);

// Builds an array, assigning user-defined time ranges to each day of week
$all_days = array("Mon" => $time_range_mon, "Tue" => $time_range_tue, "Wed" => $time_range_wed, "Thu" => $time_range_thu, "Fri" => $time_range_fri, "Sat" => $time_range_sat, "Sun" => $time_range_sun);
foreach ($all_days as &$each_day) {
    $each_day = explode("-", $each_day);
    $each_day[0] = strtotime($each_day[0]);
    $each_day[1] = strtotime($each_day[1]);
}

// Defines array of possible days of week
$week_days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");

// Compares current day of week to possible days of week and determines open vs closed output based on current day and time.
foreach ($week_days as &$each_week_day) {
        if ($status_today == $each_week_day) {
        echo '';
        if (($all_days[$each_week_day][0] <= $current_time_x) && ($all_days[$each_week_day][1] >= $current_time_x)) {

        } else {
        header( 'Location: http://www.bristolhotel.com/pizzeria/offlinepizza.php' ) ;
        }

    } 
}


推荐答案

这应该是正常的。在适当的时间内调整 $ time_range_christmas $ time_range_newyears

This should work. Adjust $time_range_christmas and $time_range_newyears with your appropriate hours.

// -------- PHP STORE HOURS ---------
// ---------- Version 1.1 -----------
// -------- BY CORY ETZKORN ---------
// -------- coryetzkorn.com ---------


// -------- EDIT FOLLOWING SECTION ONLY ---------

// Set your timezone (codes listed at http://php.net/manual/en/timezones.php)
// Delete the following line if you've already defined a timezone elsewhere.
date_default_timezone_set('Europe/Stockholm'); 

// Define daily open hours. Must be in 24-hour format, separated by dash.
$time_range_mon = '11:00-20:30';
$time_range_tue = '11:00-20:30';
$time_range_wed = '11:00-20:30';
$time_range_thu = '11:00-20:30';
$time_range_fri = '11:00-21:30';
$time_range_sat = '11:00-21:30';
$time_range_sun = '12:00-19:30';
$time_range_christmas = '12:00-14:30';
$time_range_newyears = '12:00-14:30';


// OPTIONAL: Output current day's open hours 
$echo_daily_hours = false; // Switch to FALSE to hide numerical display of current hours
$time_output = 'g a'; // Enter custom time output format (options listed here: http://php.net/manual/en/function.date.php)
$time_separator = ' - '; // Choose how to indicate range (i.e XX - XX, XX to XX, XX until XX)

// -------- END EDITING -------- 

// Gets current day of week
$status_today = date("D"); 

$todays_date = date("d M");
if ($todays_date == "25 Dec"){
    $status_today = "Christmas";
}
if ($todays_date == "1 Jan"){
    $status_today = "NewYears";
}



// Gets current time of day in 00:00 format
$current_time = date("G:i");
// Makes current time of day computer-readable
$current_time_x = strtotime($current_time);

// Builds an array, assigning user-defined time ranges to each day of week
$all_days = array("Mon" => $time_range_mon, "Tue" => $time_range_tue, "Wed" => $time_range_wed, "Thu" => $time_range_thu, "Fri" => $time_range_fri, "Sat" => $time_range_sat, "Sun" => $time_range_sun, "Christmas" => $time_range_christmas, "NewYears" => $time_range_newyears);
foreach ($all_days as &$each_day) {
    $each_day = explode("-", $each_day);
    $each_day[0] = strtotime($each_day[0]);
    $each_day[1] = strtotime($each_day[1]);
}

// Defines array of possible days of week
$week_days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Christmas", "NewYears");

// Compares current day of week to possible days of week and determines open vs closed output based on current day and time.
foreach ($week_days as &$each_week_day) {
        if ($status_today == $each_week_day) {
        echo '';
        if (($all_days[$each_week_day][0] <= $current_time_x) && ($all_days[$each_week_day][1] >= $current_time_x)) {
        } else {
            header( 'Location: http://www.bristolhotel.com/pizzeria/offlinepizza.php' ) ;
        }
    } 
}

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

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