bahaa Posted August 21, 2011 Share Posted August 21, 2011 Hello, I want to display the date in Arabic. Is there a function to convert the day of the week and month into Arabic? PHP Version 5.3.0 Regards, Link to comment Share on other sites More sharing options...
Stuart Posted August 21, 2011 Share Posted August 21, 2011 Pretty sure you could use strftime() and set the locale to something like ar_SA.UTF-8 using setlocale(). Link to comment Share on other sites More sharing options...
bahaa Posted August 21, 2011 Author Share Posted August 21, 2011 I tried that but it did not work. Link to comment Share on other sites More sharing options...
HartleySan Posted August 22, 2011 Share Posted August 22, 2011 When you say display the date in Arabic, what do you mean? Do you mean to use a particular date format, and then translate January, February, etc. to Arabic? Please give us some examples, as that might help out. Thank you. Link to comment Share on other sites More sharing options...
Pejman Ghasemi Posted August 22, 2011 Share Posted August 22, 2011 Hello Bahaa, To understand more about some unfamiliar calendars, First of all I introduce them Two different calendars use as formal calendar in middle-east : First : Lunar-Calendar(Hijri) - it uses by Muslims and Arabic countries. (As i write this post the lunar calendar is 1432,09,21) Second: Sun-Calendar(Jalali) - it uses by Persian language countries like Iran, Turkmenistan, Afghanistan and other persian language countries.... (1390,05,31) And other one is from China: Third : Chinese Lunar Calendar - it used by Chinese people however maybe a little hard and I do not understand it but this year of Rabbit. (100,07,23) I found a Gregorian Calender to Lunar Calendar converter is written by Tayeb Habib and source from www.redacacia.wordpress.com, email: tayeb.habib@gmail.com 021 // obtain month, today date etc 022 $month = (isset($month)) ? $month : date("n",time()); 023 $monthnames = array("January","February","March","April","May","June","July","August","September","October","November","December"); 024 $textmonth = $monthnames[$month - 1]; 025 $year = (isset($year)) ? $year : date("Y",time()); 026 $today = (isset($today))? $today : date("j", time()); 027 $today = ($month == date("n",time())) ? $today : 32; 028 029 // The Names of Hijri months 030 $mname = array("Muharram","Safar","Rabi'ul Awal","Rabi'ul Akhir","Jamadil Awal","Jamadil Akhir","Rajab","Sha'ban","Ramadhan","Shawwal","Zul Qida","Zul Hijja"); 031 // End of the names of Hijri months 032 033 // Setting how many days each month has 034 if ( (($month <8 ) && ($month % 2 == 1)) || (($month > 7) && ($month % 2 == 035 0)) ) $days = 31; 036 if ( (($month <8 ) && ($month % 2 == 0)) || (($month > 7) && ($month % 2 == 037 1)) ) 038 $days = 30; 039 040 //checking leap year to adjust february days 041 if ($month == 2) 042 $days = (date("L",time())) ? 29 : 28; 043 044 $dayone = date("w",mktime(1,1,1,$month,1,$year)); 045 $daylast = date("w",mktime(1,1,1,$month,$days,$year)); 046 $middleday = intval(($days-1)/2); 047 048 //checking the hijri month on beginning of gregorian calendar 049 $date_hijri = date("$year-$month-1"); 050 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 051 $smon_hijridone = $mname[$HMonths-1]; 052 $syear_hijridone = $HYear; 053 054 //checking the hijri month on end of gregorian calendar 055 $date_hijri = date("$year-$month-$days"); 056 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 057 $smon_hijridlast = $mname[$HMonths-1]; 058 $syear_hijridlast = $HYear; 059 //checking the hijri month on middle of gregorian calendar 060 $date_hijri = date("$year-$month-$middleday"); 061 list ($HDays, $HMonths, $HYear) = Hijri($date_hijri); 062 $smon_hijridmiddle = $mname[$HMonths-1]; 063 $syear_hijridmiddle = $HYear; 064 065 // checking if there's a span of a year 066 if ($syear_hijridone == $syear_hijridlast) { 067 $syear_hijridone = ""; 068 } 069 070 //checking if span of month is only one or two or three hijri months 071 if (($smon_hijridone == $smon_hijridmiddle) AND ($smon_hijridmiddle == $smon_hijridlast)) { 072 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridlast."</font>"; 073 } 074 075 if (($smon_hijridone == $smon_hijridmiddle) AND ($smon_hijridmiddle != $smon_hijridlast)) { 076 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 077 } 078 if (($smon_hijridone != $smon_hijridmiddle) AND ($smon_hijridmiddle == $smon_hijridlast)) { 079 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 080 } 081 082 if (($smon_hijridone != $smon_hijridmiddle) AND ($smon_hijridmiddle != $smon_hijridlast)) { 083 $smon_hijri = "<font color=red>".$smon_hijridone." ".$syear_hijridone."-"."-".$smon_hijridmiddle."-".$smon_hijridlast." ".$syear_hijridlast."</font>"; 084 } 085 ?> I hope it is useful article. 2 Link to comment Share on other sites More sharing options...
Larry Posted August 22, 2011 Share Posted August 22, 2011 Thanks for helping, Pejman. Very much appreciated! Link to comment Share on other sites More sharing options...
bahaa Posted August 22, 2011 Author Share Posted August 22, 2011 Thanks Pejman Very helpful Link to comment Share on other sites More sharing options...
Recommended Posts