Page 1 of 1

[SOLVED] it is a good way to do it?

Posted: Thu Nov 27, 2003 3:31 pm
by richie256
Just say me if it is a good way to code it.

Code: Select all

<?php
function GetMoisStr($Date,$Format){
$Janvier = array('Sho' => 'Janv', 'Long' => 'Janvier');
$Fevrier = array('Sho' => 'F&eacute;vr', 'Long' => 'F&eacute;vrier');
$Mars = array('Sho' => 'Mars', 'Long' => 'Mars');
$Avril = array('Sho' => 'Avr', 'Long' => 'Avril');
$Mai = array('Sho' => 'Mai', 'Long' => 'Mai');
$Juin = array('Sho' => 'Juin', 'Long' => 'Juin');
$Juillet = array('Sho' => 'Juil', 'Long' => 'Juillet');
$Aout = array('Sho' => 'Ao&ucirc;t', 'Long' => 'Ao&ucirc;t');
$Septembre = array('Sho' => 'Sept', 'Long' => 'Septembre');
$Octobre = array('Sho' => 'Oct', 'Long' => 'Octobre');
$Novembre = array('Sho' => 'Nov', 'Long' => 'Novembre');
$Decembre = array('Sho' => 'D&eacute;c', 'Long' => 'D&eacute;cembre');

switch (date("m",$Date)) {
   case 1:
      return $Janvier[$Format];
      break;
   case 2:
      return $Fevrier[$Format];
      break;
   case 3:
      return $Mars[$Format];
      break;
   case 4:
      return $Avril[$Format];
      break;
   case 5:
      return $Mai[$Format];
      break;
   case 6:
      return $Juin[$Format];
      break;
   case 7:
      return $Juillet[$Format];
      break;
   case 8:
      return $Aout[$Format];
      break;
   case 9:
      return $Septembre[$Format];
      break;
   case 10:
      return $Octobre[$Format];
      break;
   case 11:
      return $Novembre[$Format];
      break;
   case 12:
      return $Decembre[$Format];
}
}
?>

Posted: Thu Nov 27, 2003 5:02 pm
by McGruff
It's not something I've used before but take a look at the [php_man]setlocale[/php_man] fn.

Re: it is a good way to do it?

Posted: Thu Nov 27, 2003 6:33 pm
by Weirdan
richie256 wrote:Just say me if it is a good way to code it.
Hmm... it can be coded shorter.

Code: Select all

<?php
function GetMoisStr($Date,$Format){
  $months=array(
    1=> array('Sho' => 'Janv', 'Long' => 'Janvier'),
    array('Sho' => 'F&eacute;vr', 'Long' => 'F&eacute;vrier'),
    array('Sho' => 'Mars', 'Long' => 'Mars'),
    array('Sho' => 'Avr', 'Long' => 'Avril'),
    array('Sho' => 'Mai', 'Long' => 'Mai'),
    array('Sho' => 'Juin', 'Long' => 'Juin'),
    array('Sho' => 'Juil', 'Long' => 'Juillet'),
    array('Sho' => 'Ao&ucirc;t', 'Long' => 'Ao&ucirc;t'),
    array('Sho' => 'Sept', 'Long' => 'Septembre'),
    array('Sho' => 'Oct', 'Long' => 'Octobre'),
    array('Sho' => 'Nov', 'Long' => 'Novembre'),
    array('Sho' => 'D&eacute;c', 'Long' => 'D&eacute;cembre')
  );
  return $months[date("m",$Date)][$Format];
}
?>
2McGruff
setlocale isn't thread safe ;(

Posted: Fri Nov 28, 2003 6:47 am
by richie256
Thank you dude! I really apreciate it!