I thought I came up with the best solution for a workaround for PHP strftime() on Windows, and then a user reported trouble.
Windows has some limitations to strftime() and furthermore it does not support UTF-8. So I wrote a workaround for both of these issues but stumble upon charset problems.
This is what my code looks like:
function strftimefixed($format, $timestamp=null) {
if ($timestamp === null) $timestamp = time();
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // Don't mind this line
}
return mb_convert_encoding(strftime($format, $timestamp), 'UTF-8', 'auto'); // Charset is the problem
}
Error message
Warning: mb_convert_encoding(): Unable to detect character encoding
As you can see 'auto' fails to identify encoding. The user is on a Czech windows installation, but I can't hardcode it to 'ISO-8859-2' as that will only help czech users and not other end-users who don't have the slightest idea what a Windows locale is or by which charset.
So what is the best possible solution for making some universal awesome workaround?
Note: The format is not the problem here. It could be anything, like %b %e %Y %H:%M. The charset identification is the problem.