今日から5営業日先までを表示したいとすると、今日が月曜日の場合は、strtotime(‘+1 day’)、strtotime(‘+2 day’), strtotime(‘+3 day’)…とすればいいが、土日をまたぐ場合は、strtotimeをその分追加する必要があるため、date(“w”)をswitch文で分ける。
$week = array( "日", "月", "火", "水", "木", "金", "土" ); switch(date("w")){ case 0: $date = date("Y年m月d日", strtotime('+1 day')); $today = $date."(".$week[date("w", strtotime('+1 day'))].")"; $date1 = date("m/d", strtotime('+1 day')); $date1 = $date1."(".$week[date("w", strtotime('+1 day'))].")"; $date2 = date("m/d", strtotime('+2 day')); $date2 = $date2."(".$week[date("w", strtotime('+2 day'))].")"; $date3 = date("m/d", strtotime('+3 day')); $date3 = $date3."(".$week[date("w", strtotime('+3 day'))].")"; $date4 = date("m/d", strtotime('+4 day')); $date4 = $date4."(".$week[date("w", strtotime('+4 day'))].")"; $date5 = date("m/d", strtotime('+5 day')); $date5 = $date5."(".$week[date("w", strtotime('+5 day'))].")"; break; case 1: $date = date("Y年m月d日"); $today = $date."(".$week[date("w")].")"; $date1 = date("m/d"); $date1 = $date1."(".$week[date("w")].")"; $date2 = date("m/d", strtotime('+1 day')); $date2 = $date2."(".$week[date("w", strtotime('+1 day'))].")"; $date3 = date("m/d", strtotime('+2 day')); $date3 = $date3."(".$week[date("w", strtotime('+2 day'))].")"; $date4 = date("m/d", strtotime('+3 day')); $date4 = $date4."(".$week[date("w", strtotime('+3 day'))].")"; $date5 = date("m/d", strtotime('+4 day')); $date5 = $date5."(".$week[date("w", strtotime('+4 day'))].")"; break; case 2: $date = date("Y年m月d日"); $today = $date."(".$week[date("w")].")"; $date1 = date("m/d"); $date1 = $date1."(".$week[date("w")].")"; $date2 = date("m/d", strtotime('+1 day')); $date2 = $date2."(".$week[date("w", strtotime('+1 day'))].")"; $date3 = date("m/d", strtotime('+2 day')); $date3 = $date3."(".$week[date("w", strtotime('+2 day'))].")"; $date4 = date("m/d", strtotime('+3 day')); $date4 = $date4."(".$week[date("w", strtotime('+3 day'))].")"; $date5 = date("m/d", strtotime('+6 day')); $date5 = $date5."(".$week[date("w", strtotime('+6 day'))].")"; break; case 3: $date = date("Y年m月d日"); $today = $date."(".$week[date("w")].")"; $date1 = date("m/d"); $date1 = $date1."(".$week[date("w")].")"; $date2 = date("m/d", strtotime('+1 day')); $date2 = $date2."(".$week[date("w", strtotime('+1 day'))].")"; $date3 = date("m/d", strtotime('+2 day')); $date3 = $date3."(".$week[date("w", strtotime('+2 day'))].")"; $date4 = date("m/d", strtotime('+5 day')); $date4 = $date4."(".$week[date("w", strtotime('+5 day'))].")"; $date5 = date("m/d", strtotime('+6 day')); $date5 = $date5."(".$week[date("w", strtotime('+6 day'))].")"; break; case 4: $date = date("Y年m月d日"); $today = $date."(".$week[date("w")].")"; $date1 = date("m/d"); $date1 = $date1."(".$week[date("w")].")"; $date2 = date("m/d", strtotime('+1 day')); $date2 = $date2."(".$week[date("w", strtotime('+1 day'))].")"; $date3 = date("m/d", strtotime('+4 day')); $date3 = $date3."(".$week[date("w", strtotime('+4 day'))].")"; $date4 = date("m/d", strtotime('+5 day')); $date4 = $date4."(".$week[date("w", strtotime('+5 day'))].")"; $date5 = date("m/d", strtotime('+6 day')); $date5 = $date5."(".$week[date("w", strtotime('+6 day'))].")"; break; case 5: $date = date("Y年m月d日"); $today = $date."(".$week[date("w")].")"; $date1 = date("m/d"); $date1 = $date1."(".$week[date("w")].")"; $date2 = date("m/d", strtotime('+3 day')); $date2 = $date2."(".$week[date("w", strtotime('+3 day'))].")"; $date3 = date("m/d", strtotime('+4 day')); $date3 = $date3."(".$week[date("w", strtotime('+4 day'))].")"; $date4 = date("m/d", strtotime('+5 day')); $date4 = $date4."(".$week[date("w", strtotime('+5 day'))].")"; $date5 = date("m/d", strtotime('+6 day')); $date5 = $date5."(".$week[date("w", strtotime('+6 day'))].")"; break; case 6: $date = date("Y年m月d日", strtotime('+2 day')); $today = $date."(".$week[date("w", strtotime('+2 day'))].")"; $date1 = date("m/d", strtotime('+2 day')); $date1 = $date1."(".$week[date("w", strtotime('+2 day'))].")"; $date2 = date("m/d", strtotime('+3 day')); $date2 = $date2."(".$week[date("w", strtotime('+3 day'))].")"; $date3 = date("m/d", strtotime('+4 day')); $date3 = $date3."(".$week[date("w", strtotime('+4 day'))].")"; $date4 = date("m/d", strtotime('+5 day')); $date4 = $date4."(".$week[date("w", strtotime('+5 day'))].")"; $date5 = date("m/d", strtotime('+6 day')); $date5 = $date5."(".$week[date("w", strtotime('+6 day'))].")"; break; }
上手く土日がスキップされています。月末、年末でも、strtotimeなので、処理を加える必要はありません。
パラメーターによって、予定も出し分けます。
if(!empty($_GET["d"])){ $date = date("Y年m月d日", strtotime("+".$_GET["d"]." day")); $today = $date."(".$week[date("w", strtotime("+".$_GET["d"]." day"))].")"; }
4/6(金)
4/9(月)
Yes!
formへのリンク&Getパラメーターもつけて、大分出来てきました。次は管理画面側の設計と、担当者の個別ページの作成ですね。祝日の際の対応や、コメントの追加機能なども必要です。