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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
richie256
Forum Commoner
Posts: 37
Joined: Mon Oct 13, 2003 8:00 pm
Location: Montréal/Canada

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

Post 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];
}
}
?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

It's not something I've used before but take a look at the [php_man]setlocale[/php_man] fn.
Last edited by McGruff on Wed Aug 10, 2005 7:52 am, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: it is a good way to do it?

Post 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 ;(
User avatar
richie256
Forum Commoner
Posts: 37
Joined: Mon Oct 13, 2003 8:00 pm
Location: Montréal/Canada

Post by richie256 »

Thank you dude! I really apreciate it!
Post Reply