根据日期更改图像源的PHP帮助?
我想做的是展示三张图片。显示的图像取决于月份。 应该有上个月、本月和下个月的图像 这就是我所拥有的根据日期更改图像源的PHP帮助?,php,variables,date,Php,Variables,Date,我想做的是展示三张图片。显示的图像取决于月份。 应该有上个月、本月和下个月的图像 这就是我所拥有的 //Dates $prevDate = date("M Y", strtotime("-1 months")); $currDate = date("M Y"); $nextDate = date("M Y", strtotime("+1 months")); $prevMonth = $prevDate.date("M"); $currMonth = $currDate.d
//Dates
$prevDate = date("M Y", strtotime("-1 months"));
$currDate = date("M Y");
$nextDate = date("M Y", strtotime("+1 months"));
$prevMonth = $prevDate.date("M");
$currMonth = $currDate.date("M");
$nextMonth = $nectDate.date("M");
//Years
$prevYear = $prevDate.date("Y");
$currYear = $currDate.date("Y");
$nextYear = $nextDate.date("Y");
echo '<img src="./images/' + $prevMonth + '_' + $prevYear + '.jpg"/>';
//日期
$prevDate=日期(“MY”,标准时间(“1个月”);
$currDate=日期(“M Y”);
$nextDate=日期(“MY”,标准时间(“1个月”);
$prevMonth=$prevDate.date(“M”);
$currMonth=$currDate.date(“M”);
$nextMonth=$nectDate.date(“M”);
//年头
$prevYear=$prevDate.date(“Y”);
$currYear=$currDate.date(“Y”);
$nextYear=$nextDate.date(“Y”);
回声';
我最后得到的是页面上的“0”。
我已经有两年没有使用php了,所以我真的很生疏!有什么帮助吗
我想要它做的是将它连接到名为“december_2011.jpg”的图像与许多其他语言不同
是串联运算符,而不是“member of”(即->
)的语法。此外,date
的接口无论如何都是程序化的(没有对象)
考虑这一点:
function filename_of_time($time) {
return '<img src="./images/'.date('M_Y',$time).'.jpg"/>');
}
echo filename_of_time(strtotime("-1 month"));
echo filename_of_time(time());
echo filename_of_time(strtotime("+1 month"));
函数文件名\u of_time($time){
返回“”);
}
回显文件名\u的时间(strotime(“-1个月”);
回显文件名_of_time(time());
回显文件名\u的时间(strotime(“+1个月”);
与许多其他语言不同,
是串联运算符,而不是“成员”的语法(即->
)。此外,date
的接口无论如何都是程序化的(没有对象)
考虑这一点:
function filename_of_time($time) {
return '<img src="./images/'.date('M_Y',$time).'.jpg"/>');
}
echo filename_of_time(strtotime("-1 month"));
echo filename_of_time(time());
echo filename_of_time(strtotime("+1 month"));
函数文件名\u of_time($time){
返回“”);
}
回显文件名\u的时间(strotime(“-1个月”);
回显文件名_of_time(time());
回显文件名\u的时间(strotime(“+1个月”);
这段代码:
//Months
$prevMonth = date("M");
$currMonth = date("M");
$nextMonth = date("M");
将为3个变量提供相同的值:当月:“十二月”
这意味着:
//Years
$prevYear = $prevMonth.date("Y");
$currYear = $currMonth.date("Y");
$nextYear = $nextMonth.date("Y");
也会给你同样的东西:“Dec2010”(
是PHP中的串联)
最后:
echo '<img src="./images/' + $prevMonth + '_' + $prevYear + '.jpg"/>';
echo';
应该是
echo '<img src="./images/'.$prevMonth.'_'.$prevYear.'.jpg"/>';
echo';
“”用于连接,而不是像javascript中那样的“+”
您可以通过以下方式解决此问题:
//Dates
$prevDate = date("M_Y", strtotime("-1 months"));
$currDate = date("M_Y");
$nextDate = date("M_Y", strtotime("+1 months"));
echo '<img src="./images/'.$currDate.'.jpg"/>';
echo '<img src="./images/'.$prevDate.'.jpg"/>';
echo '<img src="./images/'.$nextDate.'.jpg"/>';
//日期
$prevDate=日期(“M_Y”,标准时间(“-1个月”);
$currDate=日期(“M_Y”);
$nextDate=日期(“M_Y”,标准时间(“1个月”);
回声';
回声';
回声';
为了帮助您了解它呈现的内容,.这段代码:
//Months
$prevMonth = date("M");
$currMonth = date("M");
$nextMonth = date("M");
将为3个变量提供相同的值:当月:“十二月”
这意味着:
//Years
$prevYear = $prevMonth.date("Y");
$currYear = $currMonth.date("Y");
$nextYear = $nextMonth.date("Y");
也会给你同样的东西:“Dec2010”(
是PHP中的串联)
最后:
echo '<img src="./images/' + $prevMonth + '_' + $prevYear + '.jpg"/>';
echo';
应该是
echo '<img src="./images/'.$prevMonth.'_'.$prevYear.'.jpg"/>';
echo';
“”用于连接,而不是像javascript中那样的“+”
您可以通过以下方式解决此问题:
//Dates
$prevDate = date("M_Y", strtotime("-1 months"));
$currDate = date("M_Y");
$nextDate = date("M_Y", strtotime("+1 months"));
echo '<img src="./images/'.$currDate.'.jpg"/>';
echo '<img src="./images/'.$prevDate.'.jpg"/>';
echo '<img src="./images/'.$nextDate.'.jpg"/>';
//日期
$prevDate=日期(“M_Y”,标准时间(“-1个月”);
$currDate=日期(“M_Y”);
$nextDate=日期(“M_Y”,标准时间(“1个月”);
回声';
回声';
回声';
为了帮助您了解它呈现的内容,.这并不是要修复问题,而是您输入了一个错误-$nextMonth=$nectDate,而不是$nextDate。这并不是要修复问题,而是输入了一个错误-$nextMonth=$nectDate,而不是$nextDate。