简单的PHP日历算法
看看有没有比我更优的,HOHO。
/**
* 日历
*
* Copyright(c) 2007 by 陈毅鑫(深空). All rights reserved
* To contact the author write to {@link mailto:shenkong@php.net}
* @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 = '<table border="1">';
$html .= '<tr>';
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $pre . '">-</a></td>';
$html .= '<td colspan="5">' . $date['year'] . ';' . $date['month'] . '</td>';
$html .= '<td><a href="' . $PHP_SELF . '?date=' . $next . '">+</a></td>';
$html .= '</tr>';
$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 .= '<tr>';
foreach ($value as $v) {
if ($v) {
if ($v == $date['mday']) {
$html .= '<td><b>' . $v . '</b></td>';
} else {
$html .= '<td>' . $v . '</td>';
}
} else {
$html .= '<td> </td>';
}
}
$html .= '</tr>';
}
$html .= '</table>';
echo $html;
昵称:深空
我想在我的网站http://www.zhan58.com/index.php远程file_get_contents这个页面http://bbs.zhan58.com/888.php,但是大部份时间得到的是http://bbs.zhan58.com/这个首页,我想知道是什么原因,是网速的原因吗,但是是静态的却可以
如果以判断http://bbs.zhan58.com/888.php修改时间或者大小来自动生成静态页面,应该怎么写呢,谢谢
你的888.php 里可能有HTTP头信息的验证过滤,静态的就不会
你可以尝试用其他方式去获取CURL,fscok…之类的
非常漂亮的代码!
你的空间好慢啊,哪里的空间?上面的问题我已经解决了
怎么这么久没有更新了?博主去哪里了?
相当精妙的思路。
看完,获益匪浅。我决定先看完你的博文。
我觉得你的有点复杂。
<a href="”><
<a href="”>>
SunMonTunWenThuFriSat
<?php
$current=1;
while($current<=$total_days)
{
echo '’;
for($i=0;$i<7;$i++)
{
if(($current==1&&$i$total_days)
{
echo ‘ ’;
continue;
}
echo “$current”;
$current++;
}
echo ”;
}
echo ”;
?>
sorry, 忘转义了。
<?php
$timestamp=(isset($_GET['t']))?$_GET['t']:time();
list($month, $day, $year)=explode(‘/’, date(‘m/d/Y’, $timestamp));
$first_day_in_month=date(‘w’,mktime(0, 0, 0, $month, 1, $year));
$total_days=date(‘t’, $timestamp);
?>
<table>
<tr><th colspan=”7″><a href=”<?php echo htmlspecialchars($_SERVER['PHP_SELF']).’?t=’.strtotime(‘-1 month’, $timestamp);?>”><</a> <?php echo date(‘F ‘, $timestamp).$year;?>
<a href=”<?php echo htmlspecialchars($_SERVER['PHP_SELF']).’?t=’.strtotime(‘+1 month’, $timestamp);?>”>></a></th>
</tr>
<tr><th>Sun</th><th>Mon</th><th>Tun</th><th>Wen</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>
<?php
$current=1;
while($current<=$total_days)
{
echo ‘<tr>’;
for($i=0;$i<7;$i++)
{
if(($current==1&&$i<$first_day_in_month)||$current>$total_days)
{
echo ‘<td> </td>’;
continue;
}
echo “<td>$current</td>”;
$current++;
}
echo ‘</tr>’;
}
echo ‘</table>’;
?>
粗看了你第一行代码,就知道你是个垃圾程序员
$date = isset($_GET['date']) ? $_GET['date'] : date(‘Y-m-d’);
如果$_GET['data'] = ” “怎么办?你检测了么?
isset函数好好去看看
本文主要讨论算法,具体如何检测自己写去。