<?phpfunctiondayrange($days){$wdays=array("mon","tue","wed","thu","fri","sat","sun");$indays=explode(",",str_replace(" ","",$days));// expand the list to an array$retstr=array_shift($indays);// get the first date$curpos=array_search($retstr,$wdays);// current position in the wdays array$intv=0;// interval between days to avoid mon-tue like outputforeach($indaysas$d){if($d==$wdays[$curpos]){$curpos=($curpos++)%7;// this will take care of wrapping.$intv++;}else{$retstr.=($intv>1?"-".$d:",".$d);// use appropriate join$intv=0;// reset interval}}if($intv>0){// if anything was left deal with the end.$retstr.=($intv>1?"-".$d:",".$d);}else{$retstr.=",".$d;}return($retstr);}echodayrange("mon,tue,wed,fri,sat");