fpdf multicell not showing values - php

I am creating a pdf which is working but the values are not being entered into the multicell of the pdf.
Lets take the date for example, the user enters a date and on the PDF it should look like:
Date: 26/01/2017
but this is what it looks like now:
Date:
Below is my code with the date example:
<?php
//set the question values
$questions = array(
'name' => "Name: ",
'date' => "Date: ",
'first' => "First Day of Leave: ",
'last' => "Last Day of Leave: ",
'days' => "Number of Days Taken: ",
'email' => "Managers Email: ",
'creditdays' => "Leave Days in Credit",
'personnel' => "THIS SECTION TO BE COMPLETED BY PERSONNEL DEPARTMENT",
'credit' => "Leave Days in Credit:",
'mansign' => "Signed:",
'date2' => "Date:",
'authorise' => "Authorised By:",
'date3' => "Date:",
'auth' => "Authorisation Of Leave"
);
//set the question answers
$date = $_POST['date'];
$first = $_POST['first'];
$last = $_POST['last'];
$days = $_POST['days'];
$email = $_POST['email'];
$name = $_POST['name'];
//set the question names
$questionName = $questions['name'];
$questionDate = $questions['date'];
$questionFirst = $questions['first'];
$questionLast = $questions['last'];
$questionDays = $questions['days'];
$questionEmail = $questions['email'];
$personnel = $questions['personnel'];
$credit = $questions['credit'];
$mansign = $questions['mansign'];
$date2 = $questions['date2'];
$authorise = $questions['authorise'];
$date3 = $questions['date3'];
$auth = $questions['auth'];
//Create the PDF
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
//insert fields
$pdf->SetDrawColor(100, 100, 100);
$pdf->SetFillColor(100,100,100);
$pdf->Multicell(200, 3, "Leave Application Form", "", 'C');
$pdf->Ln();
$pdf->Ln();
$pdf->MultiCell(190, 10, $questionDate, $date, 'C');

According to the fpdf manual:
MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
While in your code:
$pdf->MultiCell(190, 10, $questionDate, $date, 'C');
So $date isn't part of the txt parameter to appear in the cell.
Instead, you need to append the $date variable to the $questionDate one.
$pdf->MultiCell(190, 10, $questionDate . $date, 'C');

Related

PHP: Increment variable on date change

I'm building a class-schedule tool, where users can upload a .csv-file. I want to keep track of the dates with a variable so users can upload a schedule, which starts on the 15th of a month, for example. Therefore, I would like to increment a variable on date change. The data I receive from the csv looks like this:
array(
array(
'1',
'2019-10-15',
'Orientation / Team Building',
'371',
'',
'0',
'',
),
array(
'1',
'2019-10-16',
'Study Skills',
'371',
'',
'0',
'',
),
);
I would like to output one day at a time:
$currentMonth = date('F');
$dayOfSchedule = 0;
while ($dayOfSchedule < sizeof($schedule[$currentMonth]){
echo $schedule[$currentMonth][$dayOfSchedule][2]; //output the class etc.
}
and then increment $dayOfSchedule on the day change, but I don't know how to do that.
Any help is much appreciated!
You're probably looking for something like this:
<?php
$data = array(
array(
1,
'2019-10-16',
'Study Skills',
'371',
'',
0,
'',
),
array(
1,
'2019-10-16',
'Mathematics',
'371',
'',
0,
'',
),
array(
1,
'2019-10-15',
'Orientation / Team Building',
371,
'',
0,
'',
),
);
// map rows according to the date
$schedule = array_reduce($data, function ($accu, $row) {
$date = \DateTime::createFromFormat('Y-m-d', $row[1]);
$accu[$date->format('F')][$date->format('j')][] = $row;
return $accu;
}, []);
// sort the days and months
ksort($schedule);
array_walk($schedule, function (&$month_schedule) {
ksort($month_schedule);
});
$today = date('j'); // day of month today
if (isset($schedule[date('F')])) {
foreach ($schedule[date('F')] as $day => $rows) {
if ((int) $day >= (int) $today) {
echo " Day of Month: $day\n";
foreach ($rows as $key => $row) {
echo " Class({$key}): {$row[2]}\n";
}
}
}
echo "\n";
}

PHP Date Difference After 30 Days Error?

I have a date difference that works in minutes .. then after 1 hour goes to hours .. then after 24 hours goes to days .. then weirdly after 30 days it goes back to hours
For why?! What am I missing in this code or is this some bug?!
$d_start = new DateTime('now');
$d_end = new DateTime($last_gdate);
$d_dif = $d_start->diff($d_end);
$d_d = $d_dif->d;
$d_h = $d_dif->h;
$d_m = $d_dif->i;
if ($d_d < 1) {
if ($d_h < 1) {
$d_since = $d_m . "m";
} else {
$d_since = $d_h . "h";
}
} else {
$d_since = $d_d . "d";
}
You will notice that DateTime's diff() will restart d in the next month. You should use days if you are not going to check/honor m.
Code: (Demo)
$last_gdate = "2018-07-23 00:01:02";
$d_start = new DateTime('now');
$d_end = new DateTime($last_gdate);
$d_dif = $d_start->diff($d_end);
var_export($d_dif);
$d_d = $d_dif->days;
$d_h = $d_dif->h;
$d_m = $d_dif->i;
if ($d_d < 1) {
if ($d_h < 1) {
$d_since = $d_m . "m";
} else {
$d_since = $d_h . "h";
}
} else {
$d_since = $d_d . "d";
}
echo "\n$d_since";
Output:
DateInterval::__set_state(array(
'y' => 0,
'm' => 1,
'd' => 0,
'h' => 6,
'i' => 42,
's' => 2,
'f' => 0.002468,
'weekday' => 0,
'weekday_behavior' => 0,
'first_last_day_of' => 0,
'invert' => 1,
'days' => 31,
'special_type' => 0,
'special_amount' => 0,
'have_weekday_relative' => 0,
'have_special_relative' => 0,
))
31d

new Date into Array php

For Google Visualization I coded the JSON by hand (Messy I know) I did not think about ''s in NAME_TEAM which has recently come about an issue as my first team name was entered with an apostrophe. I have read this post and tried to implement php json_encode. I am having an issue with the dates. The new Date works fine in the old messy json format, however I get an error Fatal error: Class 'Date' when I try use anything similar for the Json_encode version. The format must be date for the visualization api to understand the values.
foreach ($data as $row) {
$dateArray = explode('-', $row['THE_DATE']);
$year = $dateArray[0];
$month = $dateArray[1] - 1;
$day = $dateArray[2];
$dataArray[] = "[new Date ($year, $month, $day), {$row['ORANGE']}, {$row['GREEN']}, '{$row['NAME_TEAM']}']";
$itemOutput[] = array(
new Date($year, $month, $day),
$row['ORANGE_SCORE'],
$row['GREEN_SCORE'],
$row['NAME_TEAM'],
);
}
echo "data.addRows(" . json_encode($itemOutput) . ");" ;
Data Table creation
function drawDashboard() {
//var data = new google.visualization.DataTable();
var data = new google.visualization.DataTable(<?php echo json_encode($itemOutput, JSON_NUMERIC_CHECK); ?>);
data.addColumn('date', 'Date');
data.addColumn('number', 'ORANGE_SCORE');
data.addColumn('number', 'GREEN_SCORE');
data.addColumn('string', 'NAME_TEAM');
// data.addRows(<?php echo '[' . implode(',', $dataArray) . ']'; ?>);
ARRAY FORMAT
{"c":[
{"Date":"new Date(2013, 9, 19)"},
{"ORANGE_SCORE":14},
{"GREEN_SCORE":7},
{"NAME_TEAM":"Trigon"}]
},
You can't use Date objects in JSON; the only way to transmit dates is via strings, but the DataTable.addRows method does not parse strings into Date objects, so you will have to convert to the full JSON structure to make this work. Here's an example:
$itemOutput = array(
'cols' => array(
array('type' => 'date', 'label' => 'Date'),
array('type' => 'number', 'label' => 'ORANGE_SCORE'),
array('type' => 'number', 'label' => 'GREEN_SCORE'),
array('type' => 'string', 'label' => 'NAME_TEAM')
),
'rows' => array()
);
foreach ($data as $row) {
$dateArray = explode('-', $row['THE_DATE']);
$year = $dateArray[0];
$month = $dateArray[1] - 1;
$day = $dateArray[2];
$itemOutput['rows'][] = array('c' => array(
array('v' => "Date($year, $month, $day)"),
array('v' => $row['ORANGE_SCORE']),
array('v' => $row['GREEN_SCORE']),
array('v' => $row['NAME_TEAM'])
));
}
Then in javascript:
var data = new google.visualization.DataTable(<?php echo json_encode($itemOutput, JSON_NUMERIC_CHECK); ?>);
If case 1 or 2, What do you want?
result is Case 2.
result link
source link
<?
/***
CREATE TABLE `24992408` (
`THE_DATE` TIMESTAMP NOT NULL DEFAULT DATE ,
`ORANGE` VARCHAR( 50 ) NOT NULL ,
`ORANGE_SCORE` INT( 11 ) NOT NULL ,
`GREEN` VARCHAR( 50 ) NOT NULL ,
`GREEN_SCORE` INT( 11 ) NOT NULL ,
`NAME_TEAM` VARCHAR( 50 ) NOT NULL
) ENGINE = MYISAM ;
INSERT INTO `24992408` (
`THE_DATE` ,
`ORANGE` ,
`ORANGE_SCORE` ,
`GREEN` ,
`GREEN_SCORE` ,
`NAME_TEAM`
)
VALUES (
'2014-07-28' , '1', '1', '1', '2', 'NAME_TEAM'
);
***/
$host = "localhost";
$name = "user";
$db = "db";
$password ="password";
function confirm_query($watever){
global $connection;
if (!$watever) {
die("Database query failed! " . mysqli_error($connection));
}
}
function select_query(){
global $connection;
$query = "SELECT * FROM `24992408` ";
$admin_set = mysqli_query($connection, $query);
confirm_query($admin_set);
return $admin_set;
}
$connection = mysqli_connect($host, $name, $password, $db);
$row = mysqli_fetch_assoc($admin_set = select_query());
$dateArray = explode('-', $row['THE_DATE']);
$year = $dateArray[0]; //echo $year; //2014
$month = $dateArray[1] - 1; //echo $month; //6
$day = $dateArray[2]; //echo $day; //28
// IN PUT
//$date1 = Date('Ymd',strtotime(sprintf('%04d%02d%02d',$year, $month, $day) ) ); //case 1
$date1 = "new Date ($year, $month, $day)"; //case 2
$dataArray[] = "[$date1, {$row['ORANGE']}, {$row['GREEN']}, '{$row['NAME_TEAM']}']";
$itemOutput[] = array( $date1, $row['ORANGE_SCORE'], $row['GREEN_SCORE'], $row['NAME_TEAM'] );
echo "data.addRows(" . json_encode($dataArray) . ");" ;
// OUT PUT
//data.addRows(["[20140628, 1, 2, 'NAME_TEAM']"]); // case 1 output
//data.addRows(["[new Date (2014, 6, 28), 1, 2, 'NAME_TEAM']"]); // case 2 output
?>

Warning: Header may not contain more than a single header, new line detected

I have a question about PHP error. I went through other similar questions, and apply it, but I still have a problem like this, so I am asking it.
Situation is like this. There is an text box called special instruction; if I put just one line it is fine to work, but if I put more than one line it causes problem like this. I put urlencode(str) to solve the problem, but it is still showed up. What do I need to change? T.T
error message is "Warning: Header may not contain more than a single header, new line detected."
if($_POST['Submit'] == 'Submit Order'){
$today = date('D M dY');
$to_time = date('h:i a');
$hours = substr($to_time, 0, -6);
$minutes = substr($to_time, -5, 2);
$seconds = substr($to_time, -2);
$total_seconds = ($hours * 3600) + ($minutes * 60) + $seconds;
$date123 = $_POST['day'];
$date_post = date('D M dY',$date123);
$time_post = $_POST['time'];
$hours_post = substr($time_post, 0, -6);
$minutes_post = substr($time_post, -5, 2);
$seconds_post = substr($time_post, -2);
$total_seconds_post = ($hours_post * 3600) + ($minutes_post * 60) + $seconds_post;
$tip_amo = $_POST["tip_amount"];
$deliv_mails = $_POST["deliv_mails"];
$coupon_no = $_POST['coupon_no'];
$minorder = $_POST['minorder'];
$subtotal_amount = $_POST['subtotal_amount'];
$payment_type = $_POST['payment_type'];
$comments = addslashes($_POST['comments']);
$coupon_code = $_REQUEST["coupon_code"];
$customer_comments = get_field(CART,"additional_text","session_id='$sessionid'");
if($comments == ''){
$comments1 = $customer_comments;
}else{
$comments1 = $comments;
}
if($time_post!='') {
if($today==$date_post){
$query = [
'day' => $date123,
'time' => $time_post,
'coupon_no' => $coupon_no,
'minorder' => $minorder,
'subtotal_amount' => $subtotal_amount,
'payment_type' => $payment_type,
'comments' => $comments1,
'coupon_code' => $coupon_code,
'tip_amount' => $tip_amo,
'deliv_mails' => $deliv_mails,
'd' => $address
];
header('Location: details_info_order.php?' . http_build_query($query));
exit;
}else{
$query = [
'day' => $date123,
'time' => $time_post,
'coupon_no' => $coupon_no,
'minorder' => $minorder,
'subtotal_amount' => $subtotal_amount,
'payment_type' => $payment_type,
'comments' => $comments1,
'coupon_code' => $coupon_code,
'tip_amount' => $tip_amo,
'deliv_mails' => $deliv_mails,
'd' => $address
];
header('Location: details_info_order.php?' . http_build_query($query));
exit;
}
}
}
Warning: Header may not contain more than a single header, new line detected. in /home4/mikehan2/public_html/mikehan7/final_checkout_block.php on line 64
it is the exact error message.
You should really use something like http_build_query(); no need to manually URL encode and no messy string concatenation, eg
$query = array(
'day' => $date123,
'time' => $time_post,
// etc
);
header('Location: details_info_order.php?' . http_build_query($query));
exit;
Some of your variables contains a multiline text, maybe COMMENTS.
Use urlencode:
'comments' => urlencode($comments1),
...

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