【发布时间】:2014-03-08 23:32:26
【问题描述】:
我在互联网上找到了这个脚本(日历),但我不知道如何将唯一的超链接(a href)提供给一个月中的不同日期。
示例:如果我点击第 14 天,我希望该链接将我重定向到 google.com
示例:如果第 20 天 = yahoo.com
...
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
?>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>">Previous</a>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">Next</a><br/>
<?php echo $monthNames[$cMonth-1].' '.$cYear; ?><br/>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ) echo "<tr>";
if($i < $startday) echo "<td></td>";
else echo "<a href='#' style='float:left; margin:0px 5px;'>". ($i - $startday + 1) . "</a>";
if(($i % 7) == 6 ) echo "</tr>";
}
?>
感谢大家的解答!
【问题讨论】: