note 43313 deleted from function.date by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 17 Jul 2004 13:19:13 +0000 |
| Subject: | note 43313 deleted from function.date by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73441@lists.php.net to get a copy of this message | ||
Note Submitter: john@getonweb.com.au
----
Here is an localised version of date() method.
What it does is:
it takes all the usual attributes for the date() method, and returns it in any modified language.
In my example it is in Bosnian language, so just to clarify,
days in array start from Sunday -> Saturday, and months from 0, Jan -> Dec.
You can of course change this to your language.
This is most useful when your specific language is not supported by setlocale() method.
You are free to modify it further... for my project I only needed these outputs, but you can add
support for attributes like: S, A, a, etc...
Use it in good health...
<?php
/*
Localised date() method.
Translates attributes D, l, M & F
*/
function datum( $format, $time=false ) {
if (!$time) $time = time();
$output = "";
# Sun -> Sat
$day_Short = array('Ned', 'Pon', 'Uto', 'Sri',
'Cet', 'Pet', 'Sub');
# Sunday -> Saturday
$day_Long = array('Nededelja', 'Ponedeljak', 'Utorak',
'Srijeda', 'Cetvrtak', 'Petak', 'Subota');
# 0, Jan -> Dec (leave the 0 alone!)
$month_Short = array(0, 'Jan', 'Feb', 'Mar', 'Apr',
'Maj', 'Jun', 'Jul', 'Aug', 'Sep',
'Okt', 'Nov', 'Dec');
# 0, January -> Decemeber (leave the 0 alone!)
$month_Long = array(0, 'Januar', 'Februar', 'Mart', 'April',
'Maj', 'Juni', 'Juli', 'August', 'Septembar',
'Oktobar', 'Novembar', 'Decembar');
for ($i=0; $i<strlen($format); $i++) {
$chr = substr($format, $i, 1);
if ( $chr === "D" ) { $output .= $day_Short[date("w",$time)];
} else if ( $chr === "l" ) { $output .= $day_Long[date("w",$time)];
} else if ( $chr === "M" ) { $output .= $month_Short[date("n",$time)];
} else if ( $chr === "F" ) { $output .= $month_Long[date("n",$time)];
} else { $output .= date("$chr",$time); }
}
return $output;
}
?>