PHP setlocale has no effect
This solution might help if you don't have shell access to the server.
If you have shell access, then Benjamin Seiller's answer is the best!
As I don't have any other possibilities (shell), I've found a solution with only PHP by using the IntlDateFormatter class.
<?php
// Example vars
$month = '6';
$year = '2014';
$fmt = new IntlDateFormatter('de_DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Berlin',
IntlDateFormatter::GREGORIAN);
$lastMonth = mktime(0, 0, 0, $month -1, 1, $year);
$showLastMonth = $fmt->format($lastMonth);
echo $showLastMonth;
setlocale having no effect in PHP
Do you have the de
locale available; what does setlocale
return for you? See: return values for setlocale().
Also, check the list of available locales (e.g. locale -a
or whatever is suitable for your OS) to see if de
is among them. Likely alternatives include de_DE
or de_DE.utf8
to name a few.
In Debian, to generate a new locale, run this command:
dpkg-reconfigure locales
and pick the ones you want.
PHP setlocale not working even with locales existing
okay, after posting this, I tried one more thing. So for those experiencing the same issue, you need to set this first before setting the new locale:
setlocale(LC_TIME, "");
setLocale not working with any language, correct local is installed
Don't be fooled by the ".utf8" part of the locale. Setlocale is for single byte functions only, they don't work well with Unicode.
Also, it matters which operating system you are using, and depending on the operating system, it matters if you use the TS or NTS build of PHP.
For internationalisation / Unicode I'd recommend using the Intl extention, it has full Unicode support and a very complete calendar IntlCalendar.
PHP setlocale() fails in browser but works in cli
After you install new locales you need to restart PHP for the new locales to work. So try restarting PHP.
PHP: date F with setlocale not working
date()
and DateTime do not respect locale
use strftime()
http://php.net/manual/en/function.strftime.php
http://php.net/manual/en/function.date.php
To format dates in other languages, you should use the setlocale() and
strftime() functions instead of date().
setlocale() not working properly with date()
From the manual about date()
To format dates in other languages, you should use the setlocale() and strftime() functions instead of date().
So use strftime()
:
print strftime("%a %d-%m-%Y");
To sum up always one day, just use a timestamp like:
for ($time = time(), $contador = 1;
$contador <= 7;
$contador++, $time = strtotime('+1 day', $time)) {
print strftime("%a %d-%m-%Y", $time)."<br />\n";
}
Related Topics
Get the Last Inserted Id Using Laravel Eloquent
Run Process With Realtime Output in PHP
How to Bind MySQLi Bind_Param Arguments Dynamically in PHP
PHP Exec Command (Or Similar) to Not Wait For Result
How to Set HTML Value Attribute (With Spaces)
MySQLi_Real_Escape_String() Expects Exactly 2 Parameters, 1 Given
Find Difference Between Two Datetimes and Format At Y-M-D H:I:S
PHP String Replace Match Whole Word
PHP: Is MySQL_Real_Escape_String Sufficient For Cleaning User Input
How to Pass Data to All Views in Laravel 5
How to Do This in Laravel, Subquery Where In
How to Remove File Extension from a Website Address
How to Check Whether Mod_Rewrite Is Enable on Server
Build Select Query With Dynamic Number of Like Conditions as a MySQLi Prepared Statement