note 89102 deleted from function.date by danbrown

From: Date: Sun, 22 Feb 2009 00:37:05 +0000
Subject: note 89102 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150943@lists.php.net to get a copy of this message
Note Submitter: bastien at selfbuild dot fr Reason: non-english ---- fonction date en français avec les mêmes paramètres et options : <?php $datefr_caracteres=array('d', 'D', 'j', 'l', 'N', 'S', 'w', 'z', 'W', 'F', 'm', 'M', 'n', 't', 'L', 'o', 'Y', 'y', 'a', 'A', 'B', 'g', 'G', 'h', 'H', 'i', 's', 'u', 'e', 'I', 'O', 'P', 'T', 'Z', 'c', 'r', 'U'); $datefr_remplacements=array('\\d', '\\D', '\\j', '\\l', '\\N', '\\S', '\\w', '\\z', '\\W', '\\F', '\\m', '\\M', '\\n', '\\t', '\\L', '\\o', '\\Y', '\\y', '\\a', '\\A', '\\B', '\\g', '\\G', '\\h', '\\H', '\\i', '\\s', '\\u', '\\e', '\\I', '\\O', '\\P', '\\T', '\\Z', '\\c', '\\r', '\\U'); $datefr_jours=array('Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'); $datefr_mois=array(1=>'Janvier', 'F&eacute;vrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Ao&ucirc;t', 'Septembre', 'Octobre', 'Novembre', 'D&eacute;cembre'); $datefr_mois3l=array(1=>'Jan', 'F&eacute;v', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Ao&ucirc;', 'Sep', 'Oct', 'Nov', 'D&eacute;c'); function date_escape($string) { global $datefr_caracteres,$datefr_remplacements; return str_replace($datefr_caracteres,$datefr_remplacements,$string); } function datefr($format,$timestamp=false) { global $datefr_cache; $datefr_cache=null; if(isset($datefr_cache[$timestamp])) { return $datefr_cache[$timestamp]; } else { global $datefr_jours,$datefr_mois,$datefr_mois3l; if(empty($timestamp)) $timestamp=time(); $offset=0; for($i=0;$i<strlen($format);$i++) { if(false===strpos('DlSFM',$format[$i])) continue; $cas=0; while($format[$i-1-$cas]=='\\') $cas++; if($cas%2==1) continue; if(!isset($datefr_cache[$timestamp][$format[$i]])) { switch($format[$i]) { case 'l': $car=date_escape($datefr_jours[date('w',$timestamp)]); break; case 'D': $car=date_escape(substr($datefr_jours[date('w',$timestamp)],0,3)); break; case 'F': $car=date_escape($datefr_mois[date('n',$timestamp)]); break; case 'M': $car=date_escape($datefr_mois3l[date('n',$timestamp)]); break; case 'S': if(date('j',$timestamp)==1) $car='\\e\\r'; else $car=''; break; default: $car=''; } $datefr_cache[$timestamp][$format[$i]]=$car; } else { $car=$datefr_cache[$timestamp][$format[$i]]; } $return.=substr($format,$offset,$i-$offset).$car; $offset=$i+1; } $return.=substr($format,$offset); $return=date($return,$timestamp); $datefr_cache[$timestamp]=$return; return $return; } } // Affiche Dimanche 1er Février 2009 echo datefr('l jS F Y',1233488304); // Affiche de le jour de la semaine en français en abrégé echo datefr('D'); ?>

« previous php.notes (#150943) next »