PHP Classes
elePHPant
Icontem

File: conv.class

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Thomas Münch  >  conv.class  >  conv.class  >  Download  
File: conv.class
Role: Class source
Content type: text/plain
Description: Convert numbers to currency or mysql date format into german date format or german date format into mysql date format
Class: conv.class
Convert date or currency values
Author: By
Last change: New functions "timestamp2german" and "timestamp2int" was added.
This functions converts a mysql database timestamp format in a human readable format.

Date: 11 years ago
Size: 3,721 bytes
 

Contents

Class file image Download
<?php

#########################################################################################
#
# PHP conv.class written by Thomas Münch
# Copyright Thomas Münch, July 2003
#
# License: Freeware.
# You can use this class for commercial and non-commercial software applications
#
#
# This class coverts values of numbers to
# currency format.
# // use $number = 17; OR $number = "17,5"; OR $number = "17.5";
# // $number = convert::ccur($number);
# // return value of number is 17.50;
#
# The next function converts a mysql date format into german date format
# (yyyy-mm-tt)->(tt.mm.yyyy)
# // use $date = 2003-07-25;
# // $date = convert::mysql2german($date);
# // return value of date is 25.07.2003;
#
# The next function converts a german date value into mysql compatible date format
# (tt.mm.yyyy)->(yyyy-mm-tt)
# // use $date = 25.07.2003;
# // $date = convert::german2mysql($date);
# // return value of date is 2003-07-25
#
#
# // The function "timestamp2german" converts a mysql database timestamp value to a human readable format with german date standard
# (20030903010101)->03.09.2003:01.01.01
# //use $timestamp = 20030903010101;
# //$timestamp = convert:timestamp2german($timestamp);
# // return value is 03.09.2003:01.01.01
#
# // The function "timestamp2int" converts a mysql database timestamp value to a human readable format with international date standard
# (20030903010101)->2003.03.09:01.01.01
# //use $timestamp = 20030903010101;
# //$timestamp = convert:timestamp2int($timestamp);
# //return value is 2003.03.09:01.01.01
#
#
#########################################################################################
class convert
   
{
    function
ccur($umr)
        {
       
$umr = str_replace(",",".",$umr);
       
$wertarray = explode(".", $umr);
       
$aftercomma = $wertarray[1];
       
$aftercommalen = strlen($aftercomma);
        if (
$aftercommalen < 2 AND $aftercommalen > 0)
            {
           
$wert = "$wertarray[0]" . "." . "$wertarray[1]" . "0";
            }
        elseif(
$aftercommalen == 2)
            {
           
$wert = $umr;
            }
        elseif(!
$aftercomma)
            {
           
$wert = "$umr" . "." . "00";
            }
        return
$wert;
        }

    function
mysql2german($mysqldate)
        {
       
$mysqldatearray = explode("-", $mysqldate);
       
$tag = $mysqldatearray[2];
       
$monat = $mysqldatearray[1];
       
$jahr = $mysqldatearray[0];
       
$germandate = $tag . "." . $monat . "." . $jahr;
        return
$germandate;
        }
    function
german2mysql($germandate)
           {
       
$germandatearray = explode(".", $germandate);
       
$tag = $germandatearray[0];
           
$monat = $germandatearray[1];
       
$jahr = $germandatearray[2];
       
$mysqldate = $jahr . "-" . $monat . "-" . $tag;
        return
$mysqldate;
        }
    function
timestamp2german($stamp)
       {
       
$jahr = substr($stamp, 0, 4);
       
$monat = substr($stamp, 4, 2);
       
$tag = substr($stamp, 6, 2);
       
$stunde = substr($stamp, 8, 2);
       
$minute = substr($stamp, 10, 2);
       
$sekunde = substr($stamp, 12, 2);

       
$stamp = $tag . "." . $monat . "." . $jahr . " " . $stunde . "." . $minute . "." . $sekunde;
        return
$stamp;
        }

    function
timestamp2int($stamp)
        {
       
$jahr = substr($stamp, 0, 4);
       
$monat = substr($stamp, 4, 2);
       
$tag = substr($stamp, 6, 2);
       
$stunde = substr($stamp, 8, 2);
       
$minute = substr($stamp, 10, 2);
       
$sekunde = substr($stamp, 12, 2);

       
$stamp = $jahr . "." . $monat . "." . $tag . " " . $stunde . "." . $minute . "." . $sekunde;
        return
$stamp;
        }


    }

?>