[英]Adjusting code that was meant for PHP 5.3 to fit in with PHP 5.2.17
My server keeps returning the error because the function is not supported. 我的服务器不断返回错误,因为不支持该功能。 I have recently found out that I cannot upgrade to PHP 5.3 until Zend Optimizer supports it; 我最近发现,在Zend Optimizer支持之前我无法升级到PHP 5.3; at the moment our server admins want to stick to the stable version of ZO for the server environment. 目前,我们的服务器管理员希望坚持服务器环境的稳定版ZO。
Can you recommend any adjustments that I can make to the code? 你能推荐我对代码做出的任何调整吗?
Fatal error: Call to undefined method DateTime::createfromformat()
This is the code: 这是代码:
$today = date('l');
if($today == 'Wednesday'){
$min = date('d/m/Y', strtotime('0 days'));
$max = date('d/m/Y', strtotime('+6 days'));
}else if($today == 'Thursday'){
$min = date('d/m/Y', strtotime('-1 days'));
$max = date('d/m/Y', strtotime('+5 days'));
}else if($today == 'Friday'){
$min = date('d/m/Y', strtotime('-2 days'));
$max = date('d/m/Y', strtotime('+4 days'));
}else if($today == 'Saturday'){
$min = date('d/m/Y', strtotime('-3 days'));
$max = date('d/m/Y', strtotime('+3 days'));
}else if($today == 'Sunday'){
$min = date('d/m/Y', strtotime('-4 days'));
$max = date('d/m/Y', strtotime('+2 days'));
}else if($today == 'Monday'){
$min = date('d/m/Y', strtotime('-5 days'));
$max = date('d/m/Y', strtotime('+1 days'));
}else if($today == 'Tuesday'){
$min = date('d/m/Y', strtotime('-6 days'));
$max = date('d/m/Y', strtotime('0 days'));
}
// check database for necessary updates
$update = mysql_query("SELECT * FROM rent WHERE colour='#3C0'");
while($row_update = mysql_fetch_array( $update )) {
$datetime_lower = DateTime::createFromFormat('d/m/Y', $min);
$datetime_upper = DateTime::createFromFormat('d/m/Y', $max);
$datetime_compare = DateTime::createFromFormat('d/m/Y g:i a', $row_update['pDate']);
if ($datetime_lower < $datetime_compare && $datetime_upper > $datetime_compare) {
// date is between do nothing
} else {
// date is not between so update
$update_result = mysql_query("UPDATE rent SET colour='#F0F0F0' WHERE id=" . $row_update['id'] . " && colour='#3C0'");
mysql_close($update_result);
}
}
How can I resolve this? 我该如何解决这个问题?
You could replace that big if/elseif block with this: 你可以用这个替换那个大的if / elseif块:
$today = date("w");
$min_mod = ($today < 3) ? -4 - $today : 3 - $today;
$max_mod = ($today < 3) ? 2 - $today : 9 - $today;
$min = strtotime("today 00:00:00 -".$min_mod." days");
$max = strtotime("today 23:59:59 +".$max_mod." days");
then below in your SQL loop: 然后在你的SQL循环中:
//$datetime_lower = DateTime::createFromFormat('d/m/Y', $min);
//$datetime_upper = DateTime::createFromFormat('d/m/Y', $max);
$compare = strtotime($row_update['pDate']);
if ($min < $compare && $max > $compare) {
// date is between do nothing
} else {
// code snipped
}
Try to replace DateTime::createFromFormat('d/m/Y', $xxx);
尝试替换DateTime::createFromFormat('d/m/Y', $xxx);
with date('d/m/Y', strtotime($xxx));
与date('d/m/Y', strtotime($xxx));
. 。
不再支持PHP <= 5.3,所以请尝试为管理员提供升级服务(让他们选择 - 稳定的Zend Optimizer或稳定的PHP解释器 - 哪个更关键?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.