我需要一个数组(日,星期和星期几)在php中它本身包含从星期五到下周的星期三的当前星期。
非常感谢您的帮助
使用此脚本,我只获得当前周(从星期日或星期一开始)的数组 - nuevo到西班牙语。
不要让这两个不同的两个星期工作
请帮助
// Name day week in Spanish
function diaespanol($valor){
$valor = strtotime($valor);
switch (date('w', $valor)){
case 0: $titleday ="Domingo"; break;
case 1: $titleday ="Lunes"; break;
case 2: $titleday ="Martes"; break;
case 3: $titleday ="Miercoles"; break;
case 4: $titleday ="Jueves"; break;
case 5: $titleday ="Viernes"; break;
case 6: $titleday ="Sabado"; break;
}
return $titleday ;
}
//name in Spanish of the month
function mesydia($valor){
$mes = substr($valor,5,+2);
$dia = substr($valor,8,+2);
switch ($mes){
case '01': $titulomes ="ene"; break;
case '02': $titulomes ="feb"; break;
case '03': $titulomes ="mar"; break;
case '04': $titulomes ="abr"; break;
case '05': $titulomes ="may"; break;
case '06': $titulomes ="jun"; break;
case '07': $titulomes ="jul"; break;
case '08': $titulomes ="ago"; break;
case '09': $titulomes ="sep"; break;
case '10': $titulomes ="oct"; break;
case '11': $titulomes ="nov"; break;
case '12': $titulomes ="dic"; break;
}
return $dia.'/'.$titulomes;
}
// current day
$dia = date('Y-m-d');
$diarecibido = $dia;
//Date of initial calendar day 7 days a week from Monday to Sunday
switch (date('w', $diasemana)){
case 0: $titleday ="Domingo";
$menos=6;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
case 1: $titleday ="Lunes";
$menos=1;
$iniciosemana = $diarecibido;
break;
case 2: $titleday ="Martes";
$menos=1;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
case 3: $titleday ="Miercoles";
$menos=2;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
case 4: $titleday ="Jueves";
$menos=3;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
case 5: $titleday ="Viernes";
$menos=4;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
case 6: $titleday ="Sabado";
$menos=5;
$iniciosemana = date("Y-m-d", strtotime("$diarecibido -$menos day"));
break;
}
//day of the week
$dia_semana = (date('w'));
//if today is not Sunday
if ($dia_semana != 0 ){
//muestra semana actual
for($i=0; $i<7; $i++){
$mostrable = date("Y-m-d", strtotime("$iniciosemana +$i day"));
$titleday=diaespanol($mostrable);
$array_nombres_dias[] = diaespanol($mostrable);
$array_fechas_dias[] = mesydia($mostrable);
}
}
//if today is Sunday
else{
//muestra semana siguiente
for ($i = 7; $i < 14; $i++) {
$mostrable =date("Y-m-d", strtotime("$iniciosemana +$i day"));
$titleday = diaespanol($mostrable);
if($titleday =='Sabado' || $titleday=='Domingo'){
$findesemana='style="background:#FF0033?';
}
else{
$findesemana= '';
}
$array_nombres_dias[] = $titleday;
$array_fechas_dias[] = mesydia($mostrable);
}
}
//I walk two arrays
$longitud = count($array_fechas_dias);
echo $longitud;
for($i=0; $i<$longitud; $i++)
{
//sack the value of each element
echo $array_fechas_dias[$i] . " - ";
echo $array_nombres_dias[$i];
echo "<br>";
}
答案 0 :(得分:0)
<?php
// today
$startDate = date('Y-m-d');
$endDate = '2015-01-31';
// check the day today and find the next day you are interested in first
function nextDayByName($dayName="Sunday", $day='')
{
if(true===empty($day))
{
$day = date('Y-m-d');
}
if(date("l") !== $dayName)
{
$dayTimestamp = strtotime("next $dayName", strtotime($day));
} else {
$dayTimestamp = strtotime($day);
}
return date('Y-m-d',$dayTimestamp);
}
function addDaysUntilNextCalendarDay($day, $dateTo)
{
return nextDayByName($day, $dateTo);
}
$allInterestedDays = array();
do
{
$startDate = nextDayByName("Friday", $startDate);
$interateDays = $startDate;
// echo $interateDays;
// exit;
$nextWednesday = addDaysUntilNextCalendarDay("Wednesday", $startDate);
do
{
$allInterestedDays[] = $interateDays;
$interateDays = date('Y-m-d', strtotime($interateDays) + 86400);
} while(strtotime($interateDays) <= strtotime($nextWednesday));
//var_dump(array( "Friday" => $startDate, "nextWednesday" => $nextWednesday ));
} while($startDate <= $endDate && nextDayByName("Friday", $startDate) <= $endDate);
var_dump($allInterestedDays);
?>
我为你做了一个解决方案。请不要让其他人为你工作。
该功能将为您提供星期五至星期三之间一个月的所有日期。我希望你能从这里到达你的解决方案。
另外作为提示,最好将语言翻译应用为php数组替换,这样您就可以包含要用于替换从英语(基本语言)到
的语言文件