note 29311 added to function.date
| From: | freesoftware at xs4all dot nl | Date: | Sun, 09 Feb 2003 16:35:48 +0000 |
| Subject: | note 29311 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43692@lists.php.net to get a copy of this message | ||
Here's another example of how to replace English month and weekday names into another language
(Dutch in this example):
function formatdate($timestamp, $format) {
$weekdays = array('zondag', 'maandag', 'dinsdag',
'woensdag', 'donderdag', 'vrijdag', 'zaterdag');
$months = array('januari', 'februari', 'maart', 'april',
'mei', 'juni', 'juli', 'augustus', 'september',
'oktober', 'november', 'december');
preg_match_all('/[\\\]*[a-zA-Z]/', $format, $character);
for($i = 0; $i < count($character[0]); $i++) {
switch ($character[0][$i]) {
case 'F':
$character[1][$i] = $months[date('n', $timestamp)-1];
break;
case 'M':
$character[1][$i] = substr($months[date('n', $timestamp)-1], 0, 3);
break;
case 'l':
$character[1][$i] = $weekdays[date('w', $timestamp)];
break;
case 'D':
$character[1][$i] = substr($weekdays[date('w', $timestamp)], 0, 3);
break;
default:
$character[1][$i] = date($character[0][$i], $timestamp);
}
}
$i = 0;
$format = preg_replace('/[\\\]*[a-zA-Z]/e', "\$character[1][\$i++]", $format);
return $format;
}
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+29311
http://master.php.net/manage/user-notes.php?action=delete+29311
http://master.php.net/manage/user-notes.php?action=reject+29311