Ayhan Kesicioğlu Ayhan Kesicioğlu - 1 month ago 12
PHP Question

When I turn name of the Month into Turkish Language in PHP, it does not look right

I want to turning the name of month into Turkish Language (like April = Nisan). I defined a function for this. It's working but Turkish month name is not look right. I think there are a Turkish language character problem. How can i fix this problem?
screen shot

My date translate function:

function tarih_formatla_unix($format,$ftarih,$kacgun) //tarih_formatla_unix("GG Ay YYYY",$date,0)
{
$ftarih = date('d.m.Y', strtotime($ftarih));
$bolisaret = ".";
$tarih = explode("$bolisaret",$ftarih);
$gun = $tarih[0];
$ay = $tarih[1];
$yil = $tarih[2];
$ftarih = mktime(0, 0, 0, $ay, ($gun+$kacgun), $yil);
$gun = date("d",$ftarih);
$ay = date("n",$ftarih) - 1; //-1 dizi 0'dan başladığı için
$yil = date("Y",$ftarih);

$turkay = array("Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık");
$enay = array("January","February","March","April","May","June","July","August","September","October","November","December");
$turkgun = array("Pazartesi","Salı","Çarşamba","Perşembe","Cuma","Cumartesi","Pazar");
$engun = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");

if ($format == "GG Ay") $TAMTARIH = $gun . " " . $turkay[$ay];
if ($format == "GG Ay YYYY") $TAMTARIH = $gun . " " . $turkay[$ay] . " " . $yil;
return $TAMTARIH;
}

Answer

There is 1 remark regarding your code and another answer which will help you with all the settings needed to be done when using UTF-8 characters.

The remark is that you can use the setlocale and strftime functions instead of using that custom function you've done.

setlocale(LC_TIME, 'tr_TR');
var_dump(strftime('%A %d %m %Y'));

More information about how to use UTF-8 encoding can be found by following this question: UTF-8 - All the way through

Comments