Zend - The PHP Company




Conversion

Add Code


newTDConv  

Type: class
Added by: magnums
Entered: 23/08/2001
Last modified: 08/12/2000
Rating: - (fewer than 3 votes)
Views: 6308
This is the Easy way to Show a Dynamic Thai or English date on web page with user friendly styles such as "dd-mm-yyy" which will show Monday 13 August 2001. It's flexible for define any syntax which you want . Try a syntax like "dd-mm-yyyy","help" to see inline usages.


<?
/*
***Class Name        : newTDConv 
***Version            : 1.5
***Description        : This is the Easy way to Show a Dynamic  Thai  or English date on web page  in normal styles such as 
***                    "dd-mm-yyy" which will  show      Monday 13 August 2001. 
***                     It's flexible for define any syntax  which you want .
**Usage             : There are two variables to use this class  ==> newTDConv($format, $country)
***                        To define $format you must use only three letter d,m,yy respectly like this "d-m-yy" 
***                      "dd-mm-yyy" , "dds-mm-yyy", "d"," m" , " yy" etc.  
***                      To define $country you must select three variable "en" ," th" ," help" the details as following: 
***                      "en"  stand for show english date, "th"  stand for show thai date. "help"  show examples.
***                                 
***                        Put the  three lines as below in your php file. :
***                                  
***                                  include ("newTDConv_class.php");
***                                  $show_date = new newTDConv("dd-mm-yyyy","en");
***                                  echo "$show_date->Show_Date" ;
***                              the result is    -->     Monday 13 August 2001 
***Author                : @2001, Mr.Satit Phermsawang  
***E-mail                :satit@wimol.ac.th
***Author Note       : Please feel free to used and modified.  if it's usefully for you  Don't forget to let me know.
*/
CLass newTDConv  {
        
/*
        **Define  properties
        */
var $Get_Value ;
var 
$Get_Date ;
var 
$Show_Date ;
    
/*
    ** methods
    */
function newTDConv($Format,$Country) {
@list (
$F$M$L) = split ('[/.-]'$Format);
$this->Get_Value=array($F,$M,$L);
switch (
$Country) {
        case 
"th":
                
$dayname=array("�ҷԵ��","�ѹ���","�ѧ���","�ظ","����ʺ��","�ء��","�����");
                
$monthname=array(
                        
"Thai_long"=>array("��Ҥ�","����Ҿѹ��""�չҤ�""����¹""����Ҥ�",
                                                
"�Զع�¹","�á�Ҥ�","�ԧ�Ҥ�""�ѹ��¹","���Ҥ�","��Ȩԡ�¹",
                                                 
"�ѹ�Ҥ�"),
                        
"Thai_short"=>array("�.�.","�.�.","��.�.","��.�.","�.�.""��.�.","�.�.","�.�.",
                                                 
"�.�.""�.�.","�.�.""�.�."),
                                                                 );
                        while ( list(
$key$val) = each($this->Get_Value) ) { 
                                    switch (
trim($val))        {
                                            case 
"d" :                        //d,ds, dds do the samething.
                                            
case "ds" :                    
                                            case 
"dds" :        $this->Get_Date=date("j") ;        break ;
                                            case 
"dd" :             
                                                           
$d_D=$dayname[date("w")];
                                                           
$d_DD="  ���  ".date("j")  ;
                                                           
$this->Get_Date$d_D.$d_DD;          break ;
                                            case 
"m" :              $this->Get_Date=$monthname["Thai_short"][date("n")];        break ;
                                            case 
"mm" :           $this->Get_Date=$monthname["Thai_long"][date("n")];           break ;
                                            case 
"y" :              $this->Get_Date=substr(date("Y")+543,2,2) ;           break ;
                                            case 
"yy" :              $this->Get_Date=date("Y")+543 ;           break ;
                                            case 
"yyyy" :        
                                                            
$y_D="�.�. " ;
                                                            
$y_DD=date("Y")+543 ;
                                                            
$this->Get_Date=$y_D.$y_DD ;           break ;
                                    default :              
$this->Get_Date="";            break;
                                                                            }                
                        
$Result[] =$this->Get_Date ;
                    } 
         
$this->Show_Date implode(" ",$Result );
        break ;
    case (
"en"):
                        while ( list(
$key$val) = each($this->Get_Value) ) { 
                                switch (
trim($val))        {
                                            case 
"d" :               $this->Get_Date=date("j") ;            break ;
                                            case 
"ds" :             $this->Get_Date=date("jS") ;        break ;
                                case 
"dd" :              $this->Get_Date=date("l j") ;          break ;
                                case 
"dds" :        $this->Get_Date=date("l jS") ;       break ;
                                case 
"m" :              $this->Get_Date=date("M") ;        break ;
                                case 
"mm" :           $this->Get_Date=date("F") ;           break ;
                                case 
"y" :
                                case 
"yy" :              $this->Get_Date=date("y") ;           break ;
                                case 
"yyyy" :       $this->Get_Date=date("Y") ;           break ;
                                default :              
$this->Get_Date="";            break;
                                            }                
                        
$Result[] =$this->Get_Date ;
                                                                        } 
     
$this->Show_Date implode(" ",$Result );
     break ;
default :                
        
 
$syntax=array("d""ds""dd""dds""m",  "mm""y""yy""yyyy"
                                 
"d-mm""mm-yyyy""yyyy",  "d-m-yy" ,"ds--m-yy""d-m-yyyy",
                                 
"ds-m-yyyy""d-mm-yyyy""ds-mm-yyyy ""dd-mm-yyyy""dds-mm-yyyy""mm-d-yyyy"
                                    
"mm-ds -yyyy" ) ;
?>
<h2>The Sample of TDConv Class v.1.5 Syntax Usage :<br>
(by,  Mr.Satit Phermsawang  <a href="mailto:satit@wimol.ac.th">e-mail: satit@wimol.ac.th</a>)</h2>
<table cellspacing="2" cellpadding="2" border="1">
<tr align=center>
    <td><b>No. </b></td>
    <td><b>Syntax </b></td>
    <td ><b>Thai</b></td>
    <td><b>English</b></td>
    </tr>
<? foreach ($syntax  as $key=> $value) { ?>
<tr>
    <td><? echo$key+.".<br>" ;  ?></td>
    <td><? echo "&quot".$value."&quot <br>" ;  ?></td>
    <td><? $show_date_th = new newTDConv($value,"th");
          echo 
"$show_date_th->Show_Date <br>" ?></td>
    <td><? $show_date_en = new newTDConv($value,"en");
          echo 
"$show_date_en->Show_Date <br>" ?></td>
</tr>
<?
}
?>
</table>                    
<?                                    

break;

   }
      }
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories