note 53788 deleted from function.date by didou
| From: | didou@php.net | Date: | Mon, 13 Jun 2005 15:50:40 +0000 |
| Subject: | note 53788 deleted from function.date by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90358@lists.php.net to get a copy of this message | ||
Note Submitter: Fernando Vieira
Reason: bad code
----
I created this function to write the month/day in the specified language. It's easy to add a
new language and change default one.
/**
* Emulates the date function with the extra language argument.
* Possible languages: br, it, en, es, fr
*
* @param string $format
* @param int $stamp
* @param string $lang
*/
function _date($format, $stamp='', $lang='br')
{
$stamp = _if($stamp, time());
switch ($lang) {
case 'br':
$days = array('Domingo', 'Segunda-feira',
'Terça-feira', 'Quarta-feira', 'Quinta-feira',
'Sexta-feira', 'Sábado');
$month = array('Janeiro', 'Fevereiro', 'Março',
'Abril', 'Maio', 'Junho', 'Julho', 'Agosto',
'Setembro', 'Outubro', 'Novembro', 'Dezembro');
break;
case 'it':
$days = array('Domenica', 'Lunedì', 'Martedì',
'Mercoledì', 'Giovedì', 'Venerdì', 'Sabato');
$month = array('Gennaio', 'Febbraio', 'Marzo',
'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto',
'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
break;
case 'es':
$days = array('domingo', 'lunes', 'martes',
'miércoles', 'jueves', 'viernes', 'sábado',
'domingo');
$month = array('enero', 'febrero', 'marzo',
'abril', 'mayo', 'junio', 'julio', 'agosto',
'septiembre', 'octubre', 'noviembre', 'diciembre');
break;
case 'fr':
$days = array('dimanche', 'lundi', 'mardi',
'mercredi', 'jeudi', 'vendredi', 'samedi');
$month = array('janvier', 'février', 'mars',
'avril', 'mai', 'juin', 'juillet', 'août',
'septembre', 'octobre', 'novembre', 'décembre');
break;
default:
$days = array('Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday');
$month = array('January', 'February', 'March',
'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December');
break;
}
$day_of_week = date('w', $stamp);
$month_number = date('n', $stamp);
$month_literal = date('F', $stamp);
$month_short = date('M', $stamp);
$day_literal = date('l', $stamp);
$day_short = date('D', $stamp);
$search = array($month_literal, $month_short, $day_literal, $day_short);
$replace = array($month[$month_number], substr($month[$month_number], 0, 3),
$days[$day_of_week], substr($days[$day_of_week], 0, 3));
$date = date($format, $stamp);
return str_replace($search, $replace, $date);
}
//default Brazilian Portuguese
$month = _date('F');
$day = _date('l');
echo '<p>', '<strong>Portuguese</strong><br />',
'month: ', $month, '<br />', 'day: ', $day,
'</p>';
//italian
$month = _date('F', '', 'it');
$day = _date('l', '', 'it');
echo '<p>', '<strong>Italian</strong><br />',
'month: ', $month, '<br />', 'day: ', $day,
'</p>';
//spanish
$month = _date('F', '', 'es');
$day = _date('l', '', 'es');
echo '<p>', '<strong>Spanish</strong><br />',
'month: ', $month, '<br />', 'day: ', $day,
'</p>';
//french
$month = _date('F', '', 'fr');
$day = _date('l', '', 'fr');
echo '<p>', '<strong>French</strong><br />',
'month: ', $month, '<br />', 'day: ', $day,
'</p>';
//english
$month = _date('F', '', 'en');
$day = _date('l', '', 'en');
echo '<p>', '<strong>English</strong><br />',
'month: ', $month, '<br />', 'day: ', $day,
'</p>';