Codice PHP:
<?php
#########################################################################################
# CLASSE DataX
# Provvede alla creazione di una striga con la data formattata come da richiesta utente
#
# PARAMETRI:
# M = mese intero (es. Gennaio)
# m = mese ridotto (es. Gen)
# c = mese in cifra (es. 01)
# S = Giorno intero (es. Lunedì)
# s = Giorno ridotto (es. Lun)
# y = Anno 2 cifre
# Y = Anno 4 cifre
# d = Giorno del mese
#
# USO:
# $data = new DataX("parametri separati da virgola", timestamp);
# $data->DataConstruct();
#
# ESEMPIO (se voglio un formato tipo Lunedì 15 Feb 2008)
# $data = new DataX("S,d,m,Y", timestamp);
#
# Se si desidera la data attuale, immettere come valore timestamp "td"
#######################################################################################
class DataX
{
var $mesi = array("zero", "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
var $mesi_rid = array("zero", "Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic");
var $giorno = array("Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato");
var $giorno_rid = array("Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab");
var $time;
var $input;
var $format;
var $mode;
var $res;
var $result = "";
function DataX ($string, $timestamp)
{
if($timestamp != "td")
{
$this->time = $timestamp;
}
else
{
$this->time = time();
}
$this->input = $string;
}
function DataConstruct()
{
$this->format = explode(",", $this->input);
$max = count($this->format);
$inc = 0;
while ($inc < $max)
{
$this->GetMode($this->format[$inc]);
$this->result .= $this->res;
$this->result .= " ";
$inc = $inc + 1;
}
echo $this->result;
}
function GetMode($form)
{
switch ($form)
{
case "M":
$this->res = $this->mesi[date("n", $this->time)];
break;
case "m":
$this->res = $this->mesi_rid[date("n", $this->time)];
break;
case "y":
$this->res = date("y", $this->time);
break;
case "Y":
$this->res = date("Y", $this->time);
break;
case "c":
$this->res = date("n", $this->time);
break;
case "d":
$this->res = date("d", $this->time);
break;
case "S":
$this->res = $this->giorno[date("w", $this->time)];
break;
case "s":
$this->res = $this->giorno_rid[date("w", $this->time)];
break;
}
}
}
?>