note 43313 added to function.date

From: Date: Thu, 17 Jun 2004 07:47:33 +0000
Subject: note 43313 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-71204@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43313 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43313&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43313&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71204) next »