• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php日历[测试通过]

php 搞代码 4年前 (2022-01-01) 35次浏览 已收录 0个评论

一直喜欢php下的日历实现代码,测试效果不错

比较不错的一款php日历代码

代码如下:
<?php
/**
* 日历
*
* Copyright(c) 2007 by 陈毅鑫(深空). All rights reserved
* To contact the author write to {@link mailto:[email protected]}
* @author 陈毅鑫(深空)
*/
if (function_exists(‘date_default_timezone_set’)) {
date_default_timezone_set(‘Asia/Chongqing’);
}
$date = isset($_GET[‘date’]) ? $_GET[‘date’] : date(‘Y-m-d’);
$date = getdate(strtotime($date));
$end = getdate(mktime(0, 0, 0, $date[‘mon’] + 1, 1, $date[‘year’]) – 1);
$start = getdate(mktime(0, 0, 0, $date[‘mon’], 1, $date[‘year’]));
$pre = date(‘Y-m-d’, $start[0] – 1);
$next = date(‘Y-m-d’, $end[0] + 86400);
$html = ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘;
$arr_tpl = array(0 => ”, 1 => ”, 2 => ”, 3 => ”, 4 => ”, 5 => ”, 6 => ”);
$date_arr = array();
$j = 0;
for ($i = 0; $i < $end['mday']; $i++) {
if (!isset($date_arr[$j])) {
$date_arr[$j] = $arr_tpl;
}
$date_arr[$j][($i+$start[‘wday’])%7] = $i+1;
if ($date_arr[$j][6]) {
$j++;
}
}
foreach ($date_arr as $value) {
$html .= ‘

‘;
foreach ($value as $v) {
if ($v) {
if ($v == $date[‘mday’]) {
$html .= ‘

‘;
} else {
$html .= ‘

‘;
}
} else {
$html .= ‘

‘;
}
}
$html .= ‘

‘;
}
$html .= ‘

‘ . $date[‘year’] . ‘;’ . $date[‘month’] . ‘+
‘ . $v . ‘‘ . $v . ‘ 

‘;
echo $html;
?>

php日历代码2

代码如下:
<?php
/**
* 日历
*/
if (function_exists(‘date_default_timezone_set’)) {
date_default_timezone_set(‘Asia/Chongqing’);
}
$date = isset($_GET[‘date’]) ? $_GET[‘date’] : date(‘Y-m-d’);
$date = getdate(strtotime($date));
$end = getdate(mktime(0, 0, 0, $date[‘mon’] + 1, 1, $date[‘year’]) – 1);
$start = getdate(mktime(0, 0, 0, $date[‘mon’], 1, $date[‘year’]));
$pre = date(‘Y-m-d’, $start[0] – 1);
$next = date(‘Y-m-d’, $end[0] + 86400);
$html = ‘<table width="200" border="1" cellspacing="0" bordercolor="#999999"
align=”center” style=”line-height:150%; font-family:Verdana,宋体; font-size: 12px;”>’;
$html .= ‘

‘;
$html .= ‘

‘;
$html .= ‘

‘ . $date[‘year’] . ‘;’ . $date[‘month’] . ‘

‘;
$html .= ‘

+

‘;
$html .= ‘

‘;
$arr_tpl = array(0 => ”, 1 => ”, 2 => ”, 3 => ”, 4 => ”, 5 => ”, 6 => ”);
$date_arr = array();
$j = 0;
for ($i = 0; $i < $end['mday']; $i++) {
if (!isset($date_arr[$j])) {
$date_arr[$j] = $arr_tpl;
}
$date_arr[$j][($i+$start[‘wday’])%7] = $i+1;
if ($date_arr[$j][6]) {
$j++;
}
}
foreach ($date_arr as $value) {
$html .= ‘

‘;
foreach ($value as $v) {
if ($v) {
if ($v == $date[‘mday’]) {
$html .= ‘

‘ . $v . ‘

‘;
} else {
$html .= ‘

‘ . $v . ‘

‘;
}
} else {
$html .= ‘

‘;
}
}
$html .= ‘

‘;
}
$html .= ‘

‘;
echo $html;
?>

下面这个也不错,提示有错误,思路清晰

代码如下:
<?php
function calendar()
{
    if($_GET[‘ym’])
    {
        $year = substr($_GET[‘ym’],0,4);
        $month = substr($_GET[‘ym’],4,(strlen($_GET[‘ym’])-4));

        if($month>12)
        {
            $year += floor($month/12);
            $month = $month % 12;
        }
        if($year > 2030) $year = 2030;
        if($year < 1980) $year = 1980;
    }

    $year = isset($year) ? $year : date(‘Y’);
    $month = isset($month) ? $month : date(‘n’);

    if($year==date(‘Y’) && $month==date(‘n’)) $today = date(‘j’);

    if($month-1 == 0)
        $prevmonth = ($year – 1).”12″;
    else $prevmonth = $year.($month – 1);

    if($month+1 == 13)
        $nextmonth = ($year+1).”1″;
    else $nextmonth = $year.($month+1);

    $prevyear = ($year – 1).$month;
    $nextyear = ($year + 1).$month;

    echo <<<VKN
        

  

    

    

    

    

    

  

  

    

    

    

    

    

    

    

  

VKN;
    $nowtime = mktime(0,0,0,$month,1,$year);//当月1号转为秒
    $daysofmonth = date(t,$nowtime);//当月天数
    $weekofbeginday = date(w,$nowtime);//当月第一天是星期几
    $weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//当月最后一天是星期几
    $daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上个月天数

    $count = 1;//计数
    //列出上月后几天
    for($i = 1 ; $i <= $weekofbeginday ; $i++)
        {
            echo     “

“;
            $count++;
        }
    //当月全部
    for($i = 1 ; $i <= $daysofmonth ; $i++)
        {
            $css = ($count%7==0 || $count%7==1)?”weekday”:”normalday”;
            if($i == $today) $css .= “today”;

            echo     “

“;
            if($count%7==0) echo “

“;
            $count++;
        }
    //下月前几天
    for ($i = 1;$i <= 6-$weekofendday;$i++)
        {
            echo     “

“;
        }

    echo <<<VKN
          

    

  

<<<$year – $month>>>
“.($daysofprevmonth-$weekofbeginday+$i).”“.$i.”
“.$i.”

VKN;
}
?>

calendar

<!–
.weekday {
    font-size: 9pt;
    color: #FF0000;
    text-align: center;
}
.normalday {
    font-size: 9pt;
    color: #000000;
    text-align: center;
}
.weekdaytoday {
    font-size: 9pt;
    color: #FF0000;
    text-align: center;
    background-color: #FFD9D9;
    font-weight: bold;
}
.normaldaytoday {
    font-size: 9pt;
    color: #000000;
    text-align: center;
    bac来源gao@daima#com搞(%代@#码网kground-color: #DDDDDD;
    font-weight: bold;
}
.othermonth {
    font-size: 9pt;
    font-style: italic;
    color: #999999;
    text-align: center;
}
–>

以上就是php日历[测试通过]的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php日历[测试通过]

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址