fesan Posted October 27, 2012 Share Posted October 27, 2012 Hi... Can i somehow change the output of php using code under? I would like the output to be in Norwegian. (Monday = Mandag) date('l', strtotime($row['dato']) Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/ Share on other sites More sharing options...
Scott_S Posted October 27, 2012 Share Posted October 27, 2012 http://php.net/manual/en/function.setlocale.php Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388107 Share on other sites More sharing options...
fesan Posted October 27, 2012 Author Share Posted October 27, 2012 Thanks... I might be using it wrong, but adding setlocale(LC_ALL, 'no_NO'); did not do the trick. I'm not sure if the host has installed the Norwegian language but it is a Norwegian host with it's servers located in Norway. On top of my index i added setlocale(LC_ALL, 'no_NO'); as the first PHP code. Also tested to add it just to the code where i want it to effect... Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388110 Share on other sites More sharing options...
salathe Posted October 27, 2012 Share Posted October 27, 2012 The date function does not change its output based on the locale, for that you want strftime. setlocale(LC_ALL, 'no_NO'); echo strftime('%A %e %B', strtotime('2012-10-29')); // mandag 29 oktober Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388122 Share on other sites More sharing options...
fesan Posted October 27, 2012 Author Share Posted October 27, 2012 ahhh.... thanks!! it appears my host doesn't have Norwegian installed. <?php setlocale(LC_ALL, 'no_NO'); echo strftime('%A %e %B', strtotime('2012-10-29')); ?> Result: Monday 29 October Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388129 Share on other sites More sharing options...
salathe Posted October 27, 2012 Share Posted October 27, 2012 If you have access to a command line on the server, run locale -a. It could be that the locale is named slightly differently, or you can generate that locale. If you don't have access to check/generate it yourself, I don't see why the host wouldn't be happy to do it for you. Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388139 Share on other sites More sharing options...
Christian F. Posted October 28, 2012 Share Posted October 28, 2012 Should the host refuse to install Norwegian locale support, for whatever silly reason (those non-vikings ), then you can use the following code to automatically translate it for you: $days ('monday' => 'Mandag', 'tuesday' => 'Tirsdag', 'wednesday' => 'Onsdag', 'thursday' => 'Torsdag', 'friday' => 'Fredag', 'saturday' => 'Lørdag', 'sunday' => 'Søndag'); $date = str_ireplace (array_keys ($days), array_values ($days), $date); Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388234 Share on other sites More sharing options...
ignace Posted October 28, 2012 Share Posted October 28, 2012 (edited) setlocale returns false when it can't set a certain locale. You can also pass multiple possibilities. Try: setlocale(LC_TIME, 'no_NO', 'no', 'nor', /* Windows: */ 'Norwegian_Norway.1252', /* Use the system locale */ '') or exit('locale does not exist'); Edited October 28, 2012 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388238 Share on other sites More sharing options...
johnnyd1963 Posted October 28, 2012 Share Posted October 28, 2012 (edited) or use $rss = $row['dato']; $dayNamesb = array("søndag", "mandag", "tirsdag", "onsdag", "torsdag", "fredag", "lørdag"); $monthNamesb = array("januar", "februar", "mars", "april", "mai", "juni", "juli", "august", "september", "oktober", "november", "desember"); $dato = $dayNamesb[date('w', strtotime($rss))] . ", " . date('d', strtotime($rss)) . " " . $monthNamesb[(date('m', strtotime($rss))-1)] . " " . date('Y', strtotime($rss)); echo $dato; this wil give you something like søndag 29 oktober 2012 Edited October 28, 2012 by johnnyd1963 Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388244 Share on other sites More sharing options...
Barand Posted October 28, 2012 Share Posted October 28, 2012 It would be a lot easier just to extend Christian's array to include month names. Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388263 Share on other sites More sharing options...
fesan Posted October 29, 2012 Author Share Posted October 29, 2012 Wow... Great guys! I'm gonna try to log inn to the shell and see if there is a other name etc. Thanks for all the help!! Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388493 Share on other sites More sharing options...
silkfire Posted October 29, 2012 Share Posted October 29, 2012 (edited) fesan you have to try all possible locale strings until you're successful. The standard NO_no rarely works. "Norwegian (Bokmål)_Norway.1252" or "norwegian-nynorsk" or "no_NO.UTF-8" or setlocale(LC_ALL, 'no_NO.ISO8859-1', 'nb_NO.ISO-8859-1', 'no', 'nb', 'nob-NO', 'no_NO', 'nb_NO', 'nor', 'norwegian', 'bokmal'); Lycka till =) Edited October 29, 2012 by silkfire Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388521 Share on other sites More sharing options...
Christian F. Posted October 29, 2012 Share Posted October 29, 2012 I'd recommend sticking to the UTF-8 charsets, and not the old ISO-8859 based ones. Saves you from having to re-encode everything generated by PHP's date/time functions. Quote Link to comment https://forums.phpfreaks.com/topic/269976-date/#findComment-1388547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.