I have a string containing multiple dates (from - to), separated by "|", example:
10.10.-29.10.2011 | 1.11.-31.11.2011
I need a code that will compare the newest start ("fr开发者_如何学Goom") date (in this case 1.11.2011) and if this date is older than current date, then replace whole string with "CLOSED".
Anyone can help me with this?Something like this?
$dates = "10.10.-29.10.2010 | 13.8.-31.11.2011 | 14.8.-31.12.2011";
$datesArr = explode(" | ",$dates);
foreach($datesArr as $k=>$date) {
$split = explode(".-",$date);
$from = explode(".",$split[0]); $to = explode(".",$split[1]);
$from = $from[0].".".$from[1].".".$to[2];
if(strtotime($from)<time()) unset($datesArr[$k]);
}
if(!empty($datesArr)) {
if(count($datesArr)==1) $dates = $datesArr[0];
else {
$dates = implode(" | ",$datesArr);
}
}
else $dates = "CLOSED";
echo $dates;
精彩评论