note 120275 added to function.strftime

From: Date: Sun, 04 Dec 2016 21:57:16 +0000
Subject: note 120275 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-208222@lists.php.net to get a copy of this message
/* Date localized. (date + lo) = datelo @param $str = date string format @param optional $locale = desired locale, depends on presence in system. Defaults to en_US @param optional $time = If needs a specific time, and not current. @returns localized translation. usage example: datelo( 'd-M-Y', 'pt_BR') internally changes to '%e-%b-%G' and returns "4-Dez-2016" (Dezembro is Portuguese word) NOTE: Flags prohibited in this version: "z" and "n", will cause to return the 'date' function version, with no translation! */ function datelo( $str, $locale='en_US', $time=null){ if( $time === null){ $time = time(); } if ( preg_match("/[DlFM]/", $str) && ! preg_match("/[nz]/", $str)){ setlocale(LC_ALL, $locale); $dict = array(); $dict['d'] = '%d'; $dict['D'] = '%a'; $dict['j'] = '%e'; $dict['l'] = '%A'; $dict['N'] = '%u'; $dict['w'] = '%w'; $dict['F'] = '%B'; $dict['m'] = '%m'; $dict['M'] = '%b'; $dict['Y'] = '%G'; $dict['g'] = '%l'; $dict['G'] = '%k'; $dict['h'] = '%I'; $dict['H'] = '%H'; $dict['i'] = '%M'; $dict['s'] = '%S'; $dict['S'] = ' '; //removes English sufixes th rd etc. $dict[' '] = ' '; $dict['-'] = '-'; $dict['/'] = '/'; $dict[':'] = ':'; $dict[','] = ','; $chars = preg_split("//", $str); $nstr = ''; foreach ($chars as $c){ if ($c){ //skip empties $nstr .= $dict[$c]; } } return strftime( $nstr); }else{ // not localized return date( $str, $time); } } ---- Server IP: 72.52.91.14 Probable Submitter: 179.110.207.245 ---- Manual Page -- http://php.net/manual/en/function.strftime.php Edit -- https://master.php.net/note/edit/120275 Del: integrated -- https://master.php.net/note/delete/120275/integrated Del: useless -- https://master.php.net/note/delete/120275/useless Del: bad code -- https://master.php.net/note/delete/120275/bad+code Del: spam -- https://master.php.net/note/delete/120275/spam Del: non-english -- https://master.php.net/note/delete/120275/non-english Del: in docs -- https://master.php.net/note/delete/120275/in+docs Del: other reasons-- https://master.php.net/note/delete/120275 Reject -- https://master.php.net/note/reject/120275 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208222) next »