2011-12-15 4 views
-5

PHP 영업 시간을 다운로드하여 평일의 영업 시간을 표시했지만 이제는 영업 시간이 다른 특정 날짜를 추가하고 싶습니다. 그걸하는 법을 모르겠다 그래서 나는 너의 도움을 바라고 있었다. 예 : 모든 일요일이 아닌 25/12 및 1/1 만 개관 시간을 변경하고 싶습니다.PHP 저장 시간, 휴관일

미리 감사드립니다.

// -------- 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') ; 
     } 

    } 
} 
+3

사람들을 당신을 위해 일하게하는 사이트가 아닙니다. – ceejayoz

+0

당신은 그 (것)들을위한 개업 시간을 2 개의 날짜를 바꾸고 싶다 그러나 당신은 말하지 않는다, 그 (것)들에 종일에 종일 당신은 폐쇄 하는가? –

+1

coryetzkorn.com에게 물어보십시오. – Toto

답변

2

이렇게하면됩니다. 적절한 시간에 $time_range_christmas$time_range_newyears을 조정하십시오.

// -------- 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') ; 
     } 
    } 
} 
+0

고마워요! 정말 도움을 주셔서 감사합니다! 메리 크리스마스! :) – jessifelt

1

또 다른 접근법입니다. time_range에 배열을 사용하고 다른 시간대로 배열을 병합하도록 스크립트를 다시 작성합니다. 제 생각에는 청결한 구성.

// -------- 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 = array(
    'mon' => '11:00-20:30', 
    'tue' => '11:00-20:30', 
    'wed' => '11:00-20:30', 
    'thu' => '11:00-20:30', 
    'fri' => '11:00-21:30', 
    'sat' => '11:00-21:30', 
    'sun' => '12:00-19:30', 
); 

$diff_times = array(
    '2011-51' = array(// Index is Y-W (Year (4 digits)-ISO week number) 
     'sat' => '11:00-15:00' // 2011-12-24 
    ), 
    '2011-52' = array(
     'sun' => '00:00-00:00' // 2011-12-25 
    ), 
); 

// 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 ISO week number (starting with monday) 
$status_this_week = date("Y-W"); 
// If we have special opening hours, they are merged into the time range array 
if (array_key_exists($status_this_week, $diff_times)) array_merge($time_range, $diff_times[$status_this_week]); 

// 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') ; 
     } 

    } 
} 
+0

25/12와 1/1을 원했지만 아이디어를 얻었으니'$ diff_time' 배열을 변경하십시오 – Alasjo

+0

고마워요! 정말 도움을 주셔서 감사합니다! 네가 무슨 뜻인지 이해해. 메리 크리스마스! :) 다시 한번 감사합니다! – jessifelt

+0

메리 크리스마스/성탄절과 새해 복 많이 받으세요! ;) – Alasjo