PHP 永久カレンダーの実装コード_PHP チュートリアル

WBOY
リリース: 2016-07-21 15:14:50
オリジナル
1673 人が閲覧しました

PHP を使用して永久カレンダー機能を実装する際の重要なポイント:

•当月の処理対象日数の合計 $days を取得する
•処理対象となる月の最初の日が $days である曜日を取得するdayofweek
$days の役割: 処理対象の月がわかる 合計何日あるかをループで出力できる

$dayofweek の役割: 曜日がわかるだけ毎月 1 日の日数を出力する前に、いくつのスペース (空白) を出力する必要があるかわかりますか

最終的なレンダリングは次のとおりです:

PHP 永久カレンダーの実装コード_PHP チュートリアル

「永久カレンダー クラス」のコードは次のとおりです:

コードをコピーします コードは次のとおりです:

/**
* PHP 永久カレンダー
* @author Fly 2012/10/16
*/
class Calendar{
protected $_table;/ /table table
protected $_currentDate;//現在の日付
protected $_year; //年
protected $_month; //月
protected $_days; // 特定の月の日数
protected $_dayofweek;// 週の 1 日指定された月
/**
* コンストラクター
*/
パブリック関数 __construct()
{
$this->_table="";
$this->_year = isset($_GET[ "y"])?$ _GET["y"]:date("Y");
$this->_month = isset($_GET["m"])?$_GET["m"]:date( "m"); ($this->_month>12){// 月が 12 より大きい場合の状況を処理します
$this->_month=1;
}
if ( $this-> ;_month$this->_month=12;
}
$this->_currentDate = $this ->_year.'year'.$this->_month.'month';//現在取得している日付情報
$this->_days = date("t",mktime(0,0,0, $this ->_month,1,$this->_year));//指定された月の日数を取得します
$this->_dayofweek = date("w",mktime(0,0,0 ,$) this->_month,1,$this->_year));//指定された月の 1 日が何曜日であるかを取得します
}
/**
* タイトルとヘッダー情報を出力します
*/
protected function _showTitle()
{
$this->_table="".$this->_currentDate."< ; /th>";
$this->_table.="";
$this->_table .="";
$this->_table .="";
$this->_table .="< td>火曜日";
$this->_table .="";
$this->_table .=""; $this->_table .=""; $this->_table.="";
}
/**
* 日付情報を出力します
* 現在の日付に基づいて日付情報を出力します
*/
保護された関数 _showDate()
{
$nums=$this-> ;_dayofweek+1; ($i=1;$i<=$this->_dayofweek;$i++){//最初の
$this->_table.="" の前の空白の日付を出力します。 ;
}
for ($i=1;$i<=$this->_days;$i++){//日情報を出力
if ($nums%7==0){ //改行処理: 7 1 行あたり
$this->_table.="
";
}else{
$this->_table .="";
}
$nums++;
}
$this->_table.="
日曜日月曜日水曜日木曜日";
$this->_table .="
金曜日土曜日
$i
";
$this-> ;_table.="< ;h3>1 月まで ;
$this->_table.="php コード 使用 関数 対処する 幾つか 成し遂げる 欲しい 要点
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!