getting month name in dutch [duplicate] - php

This question already has answers here:
Formatting DateTime object, respecting Locale::getDefault()
(6 answers)
Closed 5 years ago.
Im trying to get my date out of the DB in duth. Im spliting the date into seperate month, day and year variables and changed the month number to text but now i need to get in into dutch instead of english. I found some information on SO about it like setlocale(LC_ALL, 'nl_NL') but i cant get it to work.
<?php
include_once("db/db.php");
$statement = $db_con->prepare("select * from news_article where id > :id");
$statement->execute(array(':id' => 0));
$list = $statement->fetchAll(PDO::FETCH_ASSOC);
?>
<?php
foreach($list as $col)
{
// splitting into seperate month day year
$orderdate = explode('-', $col['datum']);
$year = $orderdate[0];
$month = $orderdate[1];
$day = $orderdate[2];
$dateObj = DateTime::createFromFormat('!m', $month);
$monthName =
$dateObj->format('F');
?>
//this needs to output in dutch
<p class="month"><?php echo $monthName ?></p>

<?php
$f = date('F');
function dutch_format($value) {
$months = array(
"January" => "januari",
"February" => "februari",
"March" => "maart",
"April" => "april",
"May" => "mei",
"June" => "juni",
"July" => "Juli",
"August" => "augustus",
"September" => "september",
"October" => "oktober",
"November" => "november",
"December" => "december"
);
return $months[$value];
}
echo $f;
echo "<br/>";
echo dutch_format($f);
?>
It will return DUTCH format. Guide me if I did any mistake

Related

How to convert array to date format in PHP? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 3 years ago.
I am getting an array in PHP as:
Array
(
[1] => 2019
[2] => 5
[3] => 7
[4] => 0
)
where [1] is always the year, [2] is always the month and [3] is always the date.
How can I convert this array to date("Y-m-d") format?
Assuming this data input:
$data = [null, 2019, 5, 7, 0];
Using DateTime
$dt = new DateTime(sprintf( "%04d-%02d-%02d", $data[1], $data[2],
$data[3]));
echo $dt->format('Y-m-d') . "\n";
Using Sprintf
// use this if you really trust the data
$dt = sprintf( "%04d-%02d-%02d", $data[0], $data[1], $data[2]);
echo $dt . "\n";
Using Carbon
// Carbon is a fantastic Date and Time class -> https://carbon.nesbot.com/
$dt = \Carbon\Carbon::create($data[0], $data[1], $data[2], 0, 0, 0);
echo $dt->format('Y-m-d') . "\n";
you can use DateTime
$timeArray = [2019,5,7,0];
$dateTime = new DateTime(printf( "%d-%d-%d", $timeArray[0],$timeArray[1],$timeArray[2] ));
echo $dateTime->format('Y-m-d'); // output: 2019-05-07
Do it like this
$arr = array( '2019', '5', '7', '0' );
echo date('Y-m-d',strtotime("$arr[0]/$arr[1]/$arr[2]"));
Although it's possible to just concatenate those values into a string and then let PHP parse that string into the Y-m-d format, I personally think mktime() is the better solution:
echo date("Y-m-d", mktime(0, 0, 0, $arr[2], $arr[3], $arr[1]));
// 2019-05-07
This removes the risk of PHP accidentally interpreting the day and month in the wrong order.
You might simply use concat and join them into a string:
$arr = array(
"1" => "2019",
"2" => "5",
"3" => "7",
"4" => "0",
);
$datetime_format = $arr["1"] . "-" . $arr["2"] . "-" . $arr["3"];
var_dump($datetime_format);
Output
string(8) "2019-5-7"
If you wish to have a 4-2-2 format, this might work:
$arr = array(
"1" => "2019",
"2" => "5",
"3" => "7",
"4" => "0",
);
$datetime_format = '';
foreach ($arr as $key => $value) {
if ($key == "4") {break;}
echo strlen($value);
if (strlen($value) >= 2) {
$datetime_format .= $value;
} elseif (strlen($value) == 2) {
$datetime_format .= $value;
} elseif (strlen($value) == 1) {
$datetime_format .= "0" . $value;
} else {
echo "Something is not right!";
}
if ($key <= "2") {$datetime_format .= '-';}
}
var_dump($datetime_format);
Output
string(10) "2019-05-07"

Compare current time with values in an array true/false

I'd like to define a set of opening hours for a 7 day week. When a visitor visits the web page I'd like to display the current time and day in a specific country (Nevis, Caribbean) and then compare it with a defined set of opening times to show one of two captions 1) Open 2) Closed. Specifically this is what I want to produce:
I'm using this so far to get the current time and set up the array but how do I compare the two?
<?php
function get_timee($country,$city) {
$country = str_replace(' ', '', $country);
$city = str_replace(' ', '', $city);
$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$city+$country,&sensor=false");
$output_deals = json_decode($geocode_stats);
$latLng = $output_deals->results[0]->geometry->location;
$lat = $latLng->lat;
$lng = $latLng->lng;
$google_time = file_get_contents("https://maps.googleapis.com/maps/api/timezone/json?location=$lat,$lng&timestamp=1331161200&key=xxx");
$timez = json_decode($google_time);
$d = new DateTime("now", new DateTimeZone($timez->timeZoneId));
return $d->format('H:i');
}
$array = array(
"Monday" => "10:00 - 18:00",
"Tuesday" => "10:00 - 18:00",
"Wednesday" => "10:00 - 18:00",
"Thursday" => "10:00 - 18:00",
"Friday" => "18:00 - 23:00",
"Saturday" => "18:00 - 23:00",
"Sunday" => "Closed"
);
?>
Its <?php echo get_timee("Federation of Saint Kitts and Nevis","Nevis"); ?>. We're currently ...
You can do all this without having to use google anything. I assume you were doing that so that you can work out the time at the clients location. Or maybe because you were not sure what the timezone on your server was set to, or you know it was set to the wrong timezone for you location.
But you can do all this using the core PHP DateTime() and DateTimeZone() classes like this.
Note: I changed the Opening/Closing times array to make it easier to process!
<?php
$opening_times = array(
"Monday" => array('open' => '10:00', 'close' => '18:00'),
"Tuesday" => array('open' => '10:00', 'close' => '18:00'),
"Wednesday" => array('open' => '10:00', 'close' => '18:00'),
"Thursday" => array('open' => '10:00', 'close' => '18:00'),
"Friday" => array('open' => '18:00', 'close' => '23:00'),
"Saturday" => array('open' => '18:00', 'close' => '23:00'),
"Sunday" => "Closed"
);
function AreWeOpen($were_open, $date)
{
$htm = '';
if ( ! is_array($were_open[$date->format('l')])
&& strtolower($were_open[$date->format('l')]) == 'closed' )
{
$htm = 'We are closed all day Sunday';
} else {
if ( $date->format('H:i') >= $were_open[$date->format('l')]['open']
&& $date->format('H:i') <= $were_open[$date->format('l')]['close']
)
{
$htm = 'We are open';
} else {
$htm = 'We are closed';
}
}
return $htm;
}
Now to run/test the above all you do is:
// set date time to NOW
$date = new DateTime(null, new DateTimeZone('America/St_Kitts'));
echo 'Are we open now? Now is ' . $date->format('l H:i') . ' >';
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open at 09:59 Monday > ';
$date = new DateTime('2015/08/17 09:59:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open at 10:00 Monday > ';
$date = new DateTime('2015/08/17 10:00:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open at 18:00 Monday > ';
$date = new DateTime('2015/08/18 18:00:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open at 18:01 Monday > ';
$date = new DateTime('2015/08/18 18:01:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open at 18:01 Friday > ';
$date = new DateTime('2015/08/21 18:01:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
echo PHP_EOL;
echo 'Are we open on SUNDAY > ';
$date = new DateTime('2015/08/16 18:01:00', new DateTimeZone('America/St_Kitts'));
echo AreWeOpen($opening_times, $date);
And that gives these results:
Are we open now? Now is Monday 07:38 >We are closed
Are we open at 09:59 Monday > We are closed
Are we open at 10:00 Monday > We are open
Are we open at 18:00 Monday > We are open
Are we open at 18:01 Monday > We are closed
Are we open at 18:01 Friday > We are open
Are we open on SUNDAY > We are closed all day Sunday
On outline of a solution:
Calculate a numerical version of your opening times array. This array would be a mapping of day of week to opening hours, indexing the days in the same time DateTime->Format('w') would, starting with 0 for Sunday, etc. Each entry could be null for no opening hours, or an array containing the number of seconds into the day at which the store opens.
Change get_timee to return the DateTime object iteself.
Determine whether the calculated DateTime object falls within the range for the current date. In particular, use (int)$dateTime->format('w') to get the index, then look that up in your numerical array. If the entry is not null, perform the "seconds" calculation for the dateTime item, and determine whether it falls within the range.

PHP Conditionally Combining Arrays

I'm looping through an array of days in the current month to generate another array of days that are on or after the current day. I'm also doing the same for the next month (which will always include all days as they are after the current date).
The complexity is when the next month is in a different year to the current month. The format of the final array is like this:
array("year" => array("month" => array(days)));
When both months are in the same year it might look like this:
$allDays = array("2013" => array( "11" => array(28,29,30), "12" => array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)));
When the 2 months are in different years (i.e. Dec and Jan) it might look like this:
$allDays = array("2013" => array("12" => array(2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31)), "2014" => array("1" => array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31) )) ;
Here's my code that generates the list of dates for the current month and the next month:
// Set the default timezone
date_default_timezone_set('Australia/Sydney');
// Get days for current month
$day = date("Y-m-d");
$i = strtotime($day);
array("year" => array("month" => array(days)));
$linked_days = array(
date('Y', $i) => array(
date('m') => range(date('d', $i), intval(date('t'))),
),
);
// Get days for next month
$day2 = date("Y-m-d", strtotime('first day of next month')) ;
$i2 = strtotime($day2);
array("year" => array("month" => array(days)));
$linked_days2 = array(
date('Y', $i2) => array(
date('m') => range(date('d', $i2), intval(date('t'))),
),
);
I'm not sure how to go about combining them into the 1 array with a different sytanx if they are in the same year or not?
You can check if there is already an entry for the year in your array with isset function :
Change this
$day2 = date("Y-m-d", strtotime('first day of next month')) ;
$i2 = strtotime($day2);
array("year" => array("month" => array(days)));
$linked_days2 = array(
date('Y', $i2) => array(
date('m') => range(date('d', $i2), intval(date('t'))),
),
);
To
$day2 = date("Y-m-d", strtotime('first day of next month')) ;
$i2 = strtotime($day2);
array("year" => array("month" => array(days))); //useless line ??
if(!isset($linked_days[date('Y', $i2)])){
//if no entry for this year in array, create new entry
$linked_days[date('Y', $i2)] = array(date('m') => range(date('d', $i), intval(date('t'))));
}
else{
//else, just add the month entry
$linked_days[date('Y', $i2)][date('m')] = range(date('d', $i2), intval(date('t'))) ;
}

Array not displaying anything when called inside another variable

I have a simple array which has been used before with no problems. Now I am trying to use it again and it is displaying nothing for text (Even in view source).
Array:
$month = Array(
1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December"
);
Code:
function getMonthlyStats($comic_id) {
require "config.php";
$query = 'SELECT *, SUM(views) AS `views` FROM '.$db_tbl_stats.' WHERE '.$db_fld_stats_comic_id.'="'.$comic_id.'" GROUP BY '.$db_fld_stats_month.' ASC';
$r_query = mysql_query($query);
while ($result = mysql_fetch_array($r_query)) {
$percent = ($result[$db_fld_stats_views]/getTotalStats($comic_id))*100;
$m = number_format($result['month']);
echo '<tr>';
echo '<td width="100"> ';
echo $month[$m];
echo '</td>';
echo '<td width="400" class="bar"><div style="width: '.$percent.'%"></div>'.$result[$db_fld_stats_views].' Views</td>';
echo '<td>'.number_format($percent).'%</td>';
echo '</tr>';
}
}
$m returns a number from 1-12 which obviously represents a month.
If you need more info I will be happy to explain more. Any help is greatly appreciated! Going on 4 hours writing and my eyes are tired.
You need to add global $month; to your function, or use $GLOBALS['month'] instead of $month.
This is called "variable scope". See http://php.net/manual/en/language.variables.scope.php for more details.

Display dates in Arabic

Here's my code:
setlocale( LC_ALL,'ar' );
echo strftime( '%e %b, %Y', strtotime( '2011-10-25' ));
Output:
25 Sep, 2011
Why is it not displaying the arabic date? Am I using strftime incorrectly?
Here you can print the Arabic PHP Date :
Create a file called arabicdate.php and place this function inside it :
function ArabicDate() {
$months = array("Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر");
$your_date = date('y-m-d'); // The Current Date
$en_month = date("M", strtotime($your_date));
foreach ($months as $en => $ar) {
if ($en == $en_month) { $ar_month = $ar; }
}
$find = array ("Sat", "Sun", "Mon", "Tue", "Wed" , "Thu", "Fri");
$replace = array ("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = date('D'); // The Current Day
$ar_day = str_replace($find, $replace, $ar_day_format);
header('Content-Type: text/html; charset=utf-8');
$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
$current_date = $ar_day.' '.date('d').' / '.$ar_month.' / '.date('Y');
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $current_date);
return $arabic_date;
}
Now include this file in your page :
include 'arabicdate.php';
Then you can print the Arabic PHP Date :
echo ArabicDate();
Live Formatted Example :
http://ideone.com/MC0hou
Hope that helps.
How about this:
function arabicDate($time)
{
$months = ["Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر"];
$days = ["Sat" => "السبت", "Sun" => "الأحد", "Mon" => "الإثنين", "Tue" => "الثلاثاء", "Wed" => "الأربعاء", "Thu" => "الخميس", "Fri" => "الجمعة"];
$am_pm = ['AM' => 'صباحاً', 'PM' => 'مساءً'];
$day = $days[date('D', $time)];
$month = $months[date('M', $time)];
$am_pm = $am_pm[date('A', $time)];
$date = $day . ' ' . date('d', $time) . ' - ' . $month . ' - ' . date('Y', $time) . ' ' . date('h:i', $time) . ' ' . $am_pm;
$numbers_ar = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"];
$numbers_en = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
return str_replace($numbers_en, $numbers_ar, $date);
}
Note: the parameter ($time) should be Unix timestamp.
AFAIK setlocale won't actually do any language translation for you but rather affects things like the formatting and comparator functionality. If you want localisation then you could try using IntlDateFormatter which may give you what you need.
Updated: You could also try Zend_Date as suggested in this question if PHP 5.3 isn't an option for you.
Inspired by Amr SubZero's answer above:
If anybody else needed this, these two functions displays post date and time in arabic for a wordpress website:
DATE:
functions.php
function single_post_arabic_date($postdate_d,$postdate_d2,$postdate_m,$postdate_y) {
$months = array("Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر");
$en_month = $postdate_m;
foreach ($months as $en => $ar) {
if ($en == $en_month) { $ar_month = $ar; }
}
$find = array ("Sat", "Sun", "Mon", "Tue", "Wed" , "Thu", "Fri");
$replace = array ("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = $postdate_d2;
$ar_day = str_replace($find, $replace, $ar_day_format);
header('Content-Type: text/html; charset=utf-8');
$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
$post_date = $ar_day.' '.$postdate_d.' '.$ar_month.' '.$postdate_y;
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $post_date);
return $arabic_date;
}
Inside the loop:
<date>
<?php
$postdate_d = get_the_date('d');
$postdate_d2 = get_the_date('D');
$postdate_m = get_the_date('M');
$postdate_y = get_the_date('Y');
echo single_post_arabic_date($postdate_d,$postdate_d2, $postdate_m, $postdate_y);
?>
</date>
TIME:
functions.php
function single_post_arabic_time($posttime_h, $posttime_i, $posttime_a) {
$ampm = array("AM", "PM");
$ampmreplace = array("ق.ظ", "ب.ظ");
$ar_ampm = str_replace($ampm, $ampmreplace, $posttime_a);
header('Content-Type: text/html; charset=utf-8');
$standardletters = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$eastern_arabic_letters = array("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩");
$post_time = $posttime_h . ':' . $posttime_i." ".$ar_ampm;
$arabic_time = str_replace($standardletters, $eastern_arabic_letters, $post_time);
return $arabic_time;
}
Inside the loop:
<span>الساعة </span>
<time>
<?php
$posttime_h = get_the_date('h');
$posttime_i = get_the_date('i');
$posttime_s = get_the_date('d');
$posttime_a = get_the_date('A');
echo single_post_arabic_time($posttime_h,$posttime_i,$posttime_a);
?>
</time>
if all you're looking for is to print what day is today, then your question is easy...
Try this function.
<?php
function arDate(){
$MONTHS = array('كانون الثاني','شباط','آذار','نيسان','أيار','حزيران','تموز','آب','أيلول','تشرين الأول','تشرين الثاني','كانون الأول');
$DAYS = array('الأحد','الاثنين','الثلاثاء','الأربعاء','الخميس','الجمعة','السبت');
$dName = date("w"); // the number of the week-day ((from 0 to 6)). [0] for Sunday, [6] for Saturday //
$dm = date("d"); // day of the month in numbers without leading zero; i.e.: 1, 2, 3... 28, 29, 30 //
$mnth = date("n")-1; // number of the month ((from 1 to 12)) this is why we minus 1 from it so that it align with our $MONTHS array.;
$yr = date('Y'); // four-digit year; eg.: 1981 //
return $DAYS[$dName] . " " . $dm . " / " . $MONTHS[$mnth] . " / " . $yr;
}
$today = arDate();
echo $today; // الأحد 01 / آب / 2021
?>
EXPLANATION:
We first prepare two arrays with arabic names of both the days and months. Then we get four variables using the PHP built-in function date(). This function has lots of parameters to control its return. I'm here using the parameters that would give me numbers so that I use them as indexes in the $MONTHS[bla bla bla] and $DAYS[bla bla bla] vars. Finally, format your arabic date to your heart content!
have a look at PHP date() function in here
NOTE1:
Do notice, please, that you can play with the arrangement of the days and months so that you don't need to minus one from your variables (-1) as I did above. Refer to the link of W3S and you would understand how to organize your arabic-name ARRAYS.
NOTE2:
Also, notice please that I'm using the Classical Arabic names in my function and which are used in Syria only; they are not so well-known in the rest of the Arab-league states though they are the classical names for months in Arabic.
Have you run
locale -a
and verified that your system has a locale called "ar"? It might be called something more specific, e.g. "ar_AR.utf8"... If you need to support Arabic locale spelled differently in multiple systems, you may pass an array to setlocale(). The first locale name in that array that the system supports will be used.
I use this javascript function if i can help:
<script type='text/javascript'>
navig = navigator.appName;
versn = parseInt(navigator.appVersion);
if ( (navig == "Netscape" && versn >= 3) || (navig == "Microsoft Internet Explorer" && versn >= 4))
info = "true";
else info = "false";
function Ar_Date() {
if (info == "true") {
var info3 = new Date();
var info4=info3.getDay();
var info5=info3.getMonth();
var info6=info3.getDate();
var info7=info3.getFullYear();
var info8 = new Array('لأحد','الإثنين','الثلاثاء','الأربعاء','الخميس','الجمعة','السبت');
var info9 = info8[info4];
var info10 = new Array('جانفي','فيفري','مارس','أفريل','ماي','جوان','جويلية','أوت','سبتمبر','أكتوبر','نوفمبر','ديسمبر');
var info11 = info10[info5];
var info12=info9+'، '+info6+' '+info11+' '+info7;
var info12=info9+'، '+info6+' '+info11;
document.write(info12);
}
}
</script>
function single_post_arabic_date($postdate_d,$postdate_d2,$postdate_m,$postdate_y) {
$months = array("01" => "يناير", "02" => "فبراير", "03" => "مارس", "04" => "أبريل", "05" => "مايو", "06" => "يونيو", "07" => "يوليو", "08" => "أغسطس", "09" => "سبتمبر", "10" => "أكتوبر", "11" => "نوفمبر", "12" => "ديسمبر");
$ar_month =months[$postdate_m];
$find = array ("Sat", "Sun", "Mon", "Tue", "Wed" , "Thu", "Fri");
$replace = array ("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = $postdate_d2;
$ar_day = str_replace($find, $replace, $ar_day_format);
header('Content-Type: text/html; charset=utf-8');
$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
$post_date = $ar_day.' '.$postdate_d.' '.$ar_month.' '.$postdate_y;
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $post_date);
return $arabic_date;
}
this is just improve function
<?php
$postdate_d = get_the_date('d');
$postdate_d2 = get_the_date('D');
$postdate_m = get_the_date('m');
$postdate_y = get_the_date('Y');
echo single_post_arabic_date($postdate_d,$postdate_d2, $postdate_m, $postdate_y);
?>
This should work:
setLocale(LC_ALL , 'ar_EG.utf-8');
If dates are still not displayed in Arabic, Then the arabic locale may not be installed on the system, To check it,connect using a terminal and type: locale -a, it would display the installed locales, if Arabic is not listed, you have to install it first and then it should work.
/**
* Convert time string to arabic
*#param string $time
*/
public function arabicDate($time)
{
$en_data = ['January', 'Jan', 'Feburary', 'Feb', 'March', 'Mar',
'April', 'Apr', 'May', 'June', 'Jun',
'July', 'Jul', 'August', 'Aug', 'September', 'Sep',
'October', 'Oct', 'November', 'Nov', 'December', 'Dec',
'Satureday', 'Sat', 'Sunday', 'Sun', 'Monday', 'Mon',
'Tuesday', 'Tue', 'Wednesday', 'Wed', 'Thursday', 'Thu', 'Friday', 'Fri',
'AM', 'am', 'PM', 'pm'
];
$ar_data = ['يناير', 'يناير', 'فبراير', 'فبراير', 'مارس', 'مارس',
'أبريل', 'أبريل', 'مايو', 'مايو', 'يونيو', 'يونيو',
'يوليو', 'يوليو', 'أغسطس', 'أغسطس', 'سبتمبر', 'سبتمبر',
'أكتوبر', 'أكتوبر', 'نوفمبر', 'نوفمبر', 'ديسمبر', 'ديسمبر',
'السبت', 'السبت', 'الأحد', 'الأحد', 'الإثنين', 'الإثنين',
'الثلاثاء', 'الثلاثاء', 'الأربعاء', 'الأربعاء', 'الخميس', 'الخميس', 'الجمعة', 'الجمعة',
'صباحاً', 'صباحاً', 'مساءً', 'مساءً'
];
return str_replace($en_data, $ar_data, $time);
}
<?php
$date = '21 Dec 22 14:13';
$date_time = new DateTime($date);
$formatter = new IntlDateFormatter('ar_DZ',);
print $formatter->format($date_time);
For more reference refer this link.
Does this work for you:
setlocale(LC_ALL,'ar');
echo strftime('%A %d %B %Y');
Hope it helps

Categories