note 92090 added to function.date

From: Date: Wed, 08 Jul 2009 10:56:23 +0000
Subject: note 92090 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-158057@lists.php.net to get a copy of this message
Slightly modified earlier written function for formatting date in russian. <?php /* these are the russian additional format characters д: full textual representation of the day of the week Д: full textual representation of the day of the week (first character is uppercase), к: short textual representation of the day of the week, К: short textual representation of the day of the week (first character is uppercase), м: full textual representation of a month М: full textual representation of a month (first character is uppercase), л: short textual representation of a month Л: short textual representation of a month (first character is uppercase), */ function date_ru($formatum, $timestamp=0) { if (($timestamp <= -1) || !is_numeric($timestamp)) return ''; $q['д'] = array(-1 => 'w', 'воскресенье','понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота'); $q['Д'] = array(-1 => 'w', 'Воскресенье','Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'); $q['к'] = array(-1 => 'w', 'вс','пн', 'вт', 'ср', 'чт', 'пт', 'сб'); $q['К'] = array(-1 => 'w', 'Вс','Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'); $q['м'] = array(-1 => 'n', '', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $q['М'] = array(-1 => 'n', '', 'Января', 'Февраля', 'Март', 'Апреля', 'Май', 'Июня', 'Июля', 'Август', 'Сентября', 'Октября', 'Ноября', 'Декабря'); $q['л'] = array(-1 => 'n', '', 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'); $q['Л'] = array(-1 => 'n', '', 'Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'); if ($timestamp == 0) $timestamp = time(); $temp = ''; $i = 0; while ( (strpos($formatum, 'д', $i) !== FALSE) || (strpos($formatum, 'Д', $i) !== FALSE) || (strpos($formatum, 'к', $i) !== FALSE) || (strpos($formatum, 'К', $i) !== FALSE) || (strpos($formatum, 'м', $i) !== FALSE) || (strpos($formatum, 'М', $i) !== FALSE) || (strpos($formatum, 'л', $i) !== FALSE) || (strpos($formatum, 'Л', $i) !== FALSE)) { $ch['д']=strpos($formatum, 'д', $i); $ch['Д']=strpos($formatum, 'Д', $i); $ch['к']=strpos($formatum, 'к', $i); $ch['К']=strpos($formatum, 'К', $i); $ch['м']=strpos($formatum, 'м', $i); $ch['М']=strpos($formatum, 'М', $i); $ch['л']=strpos($formatum, 'л', $i); $ch['Л']=strpos($formatum, 'Л', $i); foreach ($ch as $k=>$v) if ($v === FALSE) unset($ch[$k]); $a = min($ch); $temp .= date(substr($formatum, $i, $a-$i), $timestamp) . $q[$formatum[$a]][date($q[$formatum[$a]][-1], $timestamp)]; $i = $a+1; } $temp .= date(substr($formatum, $i), $timestamp); return $temp; } echo 'Сегодня '.date_ru('Д, d л Y'); ?> ---- Server IP: 78.41.104.4 Probable Submitter: 217.22.163.126 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/92090 Del: integrated -- https://master.php.net/note/delete/92090/integrated Del: useless -- https://master.php.net/note/delete/92090/useless Del: bad code -- https://master.php.net/note/delete/92090/bad+code Del: spam -- https://master.php.net/note/delete/92090/spam Del: non-english -- https://master.php.net/note/delete/92090/non-english Del: in docs -- https://master.php.net/note/delete/92090/in+docs Del: other reasons-- https://master.php.net/note/delete/92090 Reject -- https://master.php.net/note/reject/92090 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158057) next »