Last active
July 29, 2018 20:24
-
-
Save CanNuhlar/75a9f9642c547fb2d5c7b3e012da2388 to your computer and use it in GitHub Desktop.
Localize date from an English default string to Turkish using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function localize_date($date){ | |
$days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); | |
$months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
$daysLocal = array("Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi", "Pazar"); | |
$monthsLocal = array("Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"); | |
foreach($days as $key => $day){ | |
$date = str_replace($day, $daysLocal[$key], $date); | |
} | |
foreach($months as $key => $month){ | |
$date = str_replace($month, $monthsLocal[$key], $date); | |
} | |
return $date; | |
} | |
?> | |
//localize_date("Tue, 12 Apr 2016 12:32:49 +0000") returns | |
//Salı, 12 Nisan 2016 12:32:49 +0000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment