我有以下代码片段:
function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){
$first_of_month = gmmktime(0,0,0,$month,1,$year);
$day_names = array();
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400)
$day_names[$n] = ucfirst(gmstrftime('%A',$t));
$mes_pt = array('', 'Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7;
$title = htmlentities(ucfirst($mes_pt[(int)$month])).' '.$year;
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn);
if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table class="calendar">'."\n".
'<caption class="calendar-month"><h1><center><strong>'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</strong></center></h1></caption>\n<tr>";
if($day_name_length){
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Domingo</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Segunda</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Terça</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Quarta</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Quinta</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Sexta</strong></th>";
$calendar .= "<th bgcolor='black'><center><strong style='color: #FFFFFF'>Sábado</strong></th>";
$calendar .= "</tr>\n<tr>";
}
if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>';
}
我尝试更改以下代码
$day_names[$n] = ucfirst(gmstrftime('%A',$t));
和list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
通过以下代码:
$day_names[$n] = datefmt_format('%A', $t);
list($month, $year, $month_name, $weekday) = explode(',', datefmt_format('%m,%Y,%B,%w', $first_of_month));
但是运行代码时出现以下错误:
致命错误:未捕获类型错误:datefmt_format():参数 #1 ($formatter) 必须是 IntlDateFormatter 类型,给出字符串
你能帮忙解决吗?
我是这样解决问题的:
$fmt = new IntlDateFormatter(
'pt-PT',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Lisbon',
IntlDateFormatter::GREGORIAN,
'EEEE'
);
$day_names[$n] = $fmt->format($t);
$fmt1 = new IntlDateFormatter(
'pt-PT',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Lisbon',
IntlDateFormatter::GREGORIAN,
'm,Y,B,w'
);
list($month, $year, $month_name, $weekday) = explode(',',$fmt1->format($first_of_month));
我更新了这行代码
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn);
对于
$index = 0;
foreach ($pn as $key => $value) {
if ($index == 0) {
$p = $key;
$pl = $value;
}elseif ($index == 1) {
$n = $key;
$nl = $value;
}
$index++;
}