Log in

View Full Version : change variable language



remp
11-30-2007, 12:58 AM
hello, i got this variable $todayis = date("l, F j, Y, g:i a") ; and i want to know how can i change it to display the date and time in another language. (i would mostly be using spanish). Thanks

djr33
11-30-2007, 01:15 AM
Hola.

You can use the format as you want, for any international standard. Simply reformat the date, using the same setup.
http://www.php.net/manual/en/function.date.php has a long list of formatting components. 'd' for example is day of the month.
Any symbols or other characters that are NOT already used as part of the formatting will be displayed. For example, 'd:d' would output '01:01' if it was the first day of the month.

If you want to standardize the input, you can use $var = time() to get the current timestamp.

From $that, you can use date('format',$that); and output in any format you'd like.

If you are talking about actually translating words, such as days of the week, you will want to create a replacement system for the string, as I don't think that PHP has any default translation for time like that.


$todayis = date(...);
$dias = array(
'monday'=>'lunes',
'tuesday'=>'martes',
'wednesday'=>'miercoles',
'thursday'=>'jueves',
'friday'=>'viernes',
'saturday'=>'sabado',
'sunday'=>'domingo'
);
$hoyes = strtolower($todayis); //eliminate any weird capital letters
foreach ($dias as $en=>$es) {
$hoyes = str_replace($en,$es,$hoyes);
}
//$hoyes ahora esta el tiempo en espaņol

remp
11-30-2007, 02:18 AM
Thanks alot djr33!! That worked just great!! Thanks Again!!