【发布时间】:2012-01-21 05:51:54
【问题描述】:
我已经下载了 PHP 商店营业时间来显示工作日的营业时间,但现在我想添加一些不同营业时间的特定日期(你知道圣诞节快到了!:-D)但我真的不知道如何这样做,我希望能得到你的帮助。例如;我想只更改 25/12 和 1/1 的营业时间,而不是所有星期日。
提前非常感谢!
// -------- 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' ) ;
}
}
}
【问题讨论】:
-
这不是一个让人们为你工作的网站。
-
您说您想更改他们 2 个日期的营业时间,但您没有说什么,您在他们的日期全天关闭吗?
-
我已经更新了我的 PHP Store Hours 插件以允许异常日期和更强大的打开/关闭消息。干杯! coryetzkorn.com/blog/php-store-hours