当前位置:首页 » 编程语言 » php日历

php日历

发布时间: 2022-01-10 01:32:26

1. 用php编程按月显示的日历

我把我写的分享给你吧

/**
*显示日历
*@paramint$time时间戳
*/
privatefunction__calendarPanel($time=null){
$time||$time=time();
$dateinfo=getdate($time);
$calendar=array(
'year'=>$dateinfo['year'],
'month'=>$dateinfo['mon'],
'day'=>$dateinfo['mday'],
);
$m_start=strtotime(date('Y-m-01',$time));//本月第一天
$m_start_w=get_week($m_start,true);//本月第一天星期索引,0表示星期日
$m_end=strtotime('+1month',$m_start)-86400;//本月最后一天
$m_end_w=get_week($m_end,true);//本月最后一天星期索引,0表示星期日
//补齐上月日期
for($i=0;$i<$m_start_w;$i++){
$calendar['days'][]=array(
'style'=>'bef_month',
'day'=>abs(date('d',$m_start-($m_start_w-$i)*86400)),
);
}
//本月日期
for($i=$m_start;$i<=$m_end;$i+=86400){
$calendar['days'][]=array(
'style'=>'the_month'.(date('d',$i)==$calendar['day']?"bold":""),
'day'=>abs(date('d',$i)),
);
}
//补齐下月日期
for($i=$m_end_w+1;$i<=6;$i++){
$calendar['days'][]=array(
'style'=>'aft_month',
'day'=>abs(date('d',$m_end+($i-$m_end_w)*86400)),
);
}
return$calendar;
}




日历都存到返回的一个数组里了,你打印的时候,一行放7列,第一列星期日

2. 如何用PHP制作日历

calendar.class.php
代码如下:
<?php
classCalendar{
private$year;//当前的年
private$month;//当前的月
private$start_weekday;//当月的第一天对应的是周几
private$days;//当前月一共多少天

function__construct(){
$this->year=isset($_GET["year"])?$_GET["year"]:date("Y");
$this->month=isset($_GET["month"])?$_GET["month"]:date("m");

$this->start_weekday=date("w",mktime(0,0,0,$this->month,1,$this->year));
$this->days=date("t",mktime(0,0,0,$this->month,1,$this->year));
}

functionout(){
echo'<tablealign="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo'</table>';
}

privatefunctionweeksList(){
$week=array('日','一','二','三','四','五','六');

echo'<tr>';
for($i=0;$i<count($week);$i++)
echo'<thclass="fontb">'.$week[$i].'</th>';

echo'</tr>';
}

privatefunctiondaysList(){
echo'<tr>';
//输出空格(当前一月第一天前面要空出来)
for($j=0;$j<$this->start_weekday;$j++)
echo'<td></td>';


for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d'))
echo'<tdclass="fontb">'.$k.'</td>';
else
echo'<td>'.$k.'</td>';

if($j%7==0)
echo'</tr><tr>';

}

//后面几个空格
while($j%7!==0){
echo'<td></td>';
$j++;
}

echo'</tr>';
}

privatefunctionprevYear($year,$month){
$year=$year-1;

if($year<1970)
$year=1970;

return"year={$year}&month={$month}";
}


privatefunctionprevMonth($year,$month){
if($month==1){
$year=$year-1;

if($year<1970)
$year=1970;

$month=12;
}else{
$month--;
}

return"year={$year}&month={$month}";
}


privatefunctionnextYear($year,$month){
$year=$year+1;

if($year>2038)
$year=2038;

return"year={$year}&month={$month}";
}


privatefunctionnextMonth($year,$month){
if($month==12){
$year++;

if($year>2100)
$year=2100;

$month=1;
}else{
$month++;
}


return"year={$year}&month={$month}";
}

privatefunctionchageDate($url=""){
echo'<tr>';
echo'<td><ahref="?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdcolspan="3">';
echo'<form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($sy=1970;$sy<=2100;$sy++){
$selected=($sy==$this->year)?"selected":"";
echo'<option'.$selected.'value="'.$sy.'">'.$sy.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
echo'<option'.$selected1.'value="'.$sm.'">'.$sm.'</option>';
}
echo'</select>';
echo'</form>';
echo'</td>';


echo'<td><ahref="?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'<td><ahref="?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
echo'</tr>';
}

}
?>test.php

代码如下:
<style>
table{
border:1pxsolid#050;
}

.fontb{
color:white;
background:blue;
}


th{
width:30px;
}

td,th{
height:30px;
text-align:center;

}
form{
margin:0px;
padding:0px;
}
</style>
<?php
include"calendar.class.php";

$calendar=newCalendar;

$calendar->out();
?>

3. PHP万年历

出门右转,好走不送

4. php中将一年12个月的日历全部输出。如何做

<?php
//SKY8G提供
function cal_days_in_year($year){
$days=0;
for($month=1;$month<=12;$month++){
$days = $days + cal_days_in_month(CAL_GREGORIAN,$month,$year);
}
return $days;
}
//闰年
echo "这是闰年一年有:".cal_days_in_year(2000)."天";
echo "\n";
//平年
echo "这是平年一年有:".cal_days_in_year(1999)."天";
echo "\n";
//2019年
echo "今年2019年有:".cal_days_in_year(date('Y',time()))."天";
echo "\n";
//接下来我们是用php的内置函数cal_days_in_month()
$d=cal_days_in_month(CAL_GREGORIAN,2,2010);
echo "2010 年平年 2 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,2,2000);
echo "2000 年闰年 2 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2010);
echo "2010 年平年 4 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2000);
echo "2000 年闰年 4 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2010);
echo "2010 年平年 8 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2000);
echo "2000 年闰年 8 月有 $d 天。";
//详情如果想了解详情去sky8g网观看,希望对你有帮助!

5. php项目 日历

PHP 日历实现代码
<?php
$monthoneday=date("Ym")."01";
$oneweekday=date("w",strtotime($monthoneday)); //获得本月1号星期几
$monthday=date("t"); //本月多少天
$startlow=($oneweekday==0)?7:$oneweekday; //从第几列开始
for($a=1,$b=$startlow;$a<=$monthday;$a++,$b++){
$ary[$b]=$a; //用数组控制日期在哪里输出
}
$c=1;
//输出行数等于当月天数除7取整再加1
for($a=1;$a<=(int)($monthday/7)+1;$a++){
echo "<tr>";
//用数组的key来控制输出
for($b=1;$b<=7;$b++,$c++){
if($ary[$c]==date("j")){
echo '<td id="today">';
}else{
echo "<td>";
}
echo $ary[$c];
echo "</td>";
echo "\n";
}
echo "</tr>";
}
?>
参考文献http://bbs.hounwang.com/

6. php日历插件的制作方法,求思路

<?phpheader("content-type:text/html;charset=utf-8");?>
<?php?>
<tableclass="tabletable-stripedtable-hover">
<?php
//注:32位机器或者32位PHP版本可能只能计算到2038年之前的月份
//若没有GET方法传入参数,则使用服务器本地当前日期;否则使用传入的参数,方便跳转月份
$year=date("Y");
$month=date("n");
$alert="<divclass='alertalert-warning'>输入的日期格式有误!</div>";
$alertYear="<divclass='alertalert-warning'>无法计算1901年以前的日历!</div>";
if($_REQUEST){
$year=$_REQUEST["year"];
$month=$_REQUEST["month"];
}
if(!in_array($month,array("1","2","3","4","5","6","7","8","9","10","11","12"))){echo$alert;exit;}
if($year<1901){echo$alertYear;exit;}
?>
<caption><h4><?phpecho$year;?>&nbsp;年&nbsp;<?phpecho$month;?>&nbsp;月</h4></caption>
<?php
//计算当前日期,当月天数,获得星期数据,将默认星期天数字0改为7,方便处理循环
$today=date("j");
$days=date("t",strtotime("$year-$month-01"));
$week=date("w",strtotime("$year-$month-01"));
if($week==0){$week=7;}
?>
<tr>
<th>一</th>
<th>二</th>
<th>三</th>
<th>四</th>
<th>五</th>
<th>六</th>
<th>日</th>
</tr>
<tr>
<?php
//插入空白无日期区域,循环次数为当前月第一天的星期数-1
for($space=1;$space<$week;$space++){
echo"<td>-</td>";
}
//循环插入数据,当到达周日时换行输出;标记当前日期为红色
for($day=1;$day<=$days;$day++){
if(($day+$week-1)%7===0){
if($day==$today&&$year==date("Y")&&$month==date("n")){
echo"<tdstyle='background-color:pink;'>$day</td>";
echo"</tr>";
echo"<tr>";
}
echo"<td>$day</td>";
echo"</tr>";
echo"<tr>";
}else{
if($day==$today&&$year==date("Y")&&$month==date("n")){
echo"<tdstyle='background-color:pink;'>$day</td>";
}else{
echo"<td>$day</td>";
}
}
}
//尾部补足
$spacing=36-$days-$week<0?43-$days-$week:36-$days-$week;
for($footer=1;$footer<=$spacing;$footer++){
echo"<td>-</td>";
}
?>
</tr>
</table>

我以前写的,你随意看看~~

7. php怎么做日历

sybase_connect连上数据库
语法: int sybase_connect(string [servername], string [username], string [password]);
返回值: 整数函数种类: 数据库功能 本函数用来打开与 Sybase 数据库的连接。
参数 servername 为欲连上的数据库服务器名称。
参数 username 及 password 可省略,分别为连接使用的帐号及密码。
使用本函数需注意早点关闭数据库,以减少系统的负担。
连接成功则返回数据库的连接代号,失败返回 false 值。

8. HTML5+PHP要怎么制作日历

JS有个dataPicker控件,如果是自己来做需要写循环判断算法

9. 制作一个php代码要求是实现日历功能

PHP写的日历代码,网上有很多,有简单也有复杂的,具体的代码要看你的需要来确定。

考虑到做课题的话,个人推荐使用《PHP经典实例》一书中第3章最后一节,有个完整的 日历 的代码,建议你可以拿来参考,并且建议将该书第3章的内容都看一下。

《PHP经典实例》网上有电子版。

热点内容
单片机android 发布:2024-09-20 09:07:24 浏览:763
如何提高三星a7安卓版本 发布:2024-09-20 08:42:35 浏览:662
如何更换服务器网站 发布:2024-09-20 08:42:34 浏览:309
子弹算法 发布:2024-09-20 08:41:55 浏览:287
手机版网易我的世界服务器推荐 发布:2024-09-20 08:41:52 浏览:815
安卓x7怎么边打游戏边看视频 发布:2024-09-20 08:41:52 浏览:160
sql数据库安全 发布:2024-09-20 08:31:32 浏览:91
苹果连接id服务器出错是怎么回事 发布:2024-09-20 08:01:07 浏览:505
编程键是什么 发布:2024-09-20 07:52:47 浏览:655
学考密码重置要求的证件是什么 发布:2024-09-20 07:19:46 浏览:479