<?php
 
/**
 
 *  Funzioni utili per le stringhe
 
 * 
 
 * @author Dario Mazzeo <dmazzeo@ingele.com>
 
 * @version 1.0.0
 
 * @copyright Freesoftware Italia - www.freesoftwareitalia.it
 
 */ 
 
 
/**
 
 * Questa funzione controlla se una data è stata scritta correttamente
 
 *
 
 * Esempio:
 
 * 
 
 * <code>
 
 * $mydata = '31/12/2005';
 
 * if (str_isdate($mydata)) echo "Data scritta correttamente";
 
 * </code>
 
 * 
 
 * @param string $mydata Data da controllare
 
 * @return bool Restituisce true se la data è nel formato GG/MM/AAAA, false altrimenti
 
 */
 
function str_isdate($mydata){
 
    if (preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}/',$mydata) && mktime(0,0,0,
 
                                                                $mydata[3].$mydata[4],
 
                                                                $mydata[0].$mydata[1],
 
                                                                $mydata[6].$mydata[7].$mydata[8].$mydata[9])>0)
 
        return true;
 
    else 
 
        return false;
 
}
 
 
/**
 
 * Questa funzione aggiunge degli spazi alla fine della stringa
 
 * 
 
 * Esempio:
 
 * 
 
 * <code>
 
 * $testo = 'ciao';
 
 * $testo2 = str_space($testo, 20);
 
 * echo $testo2; 
 
 * </code>
 
 * 
 
 * Da utilizzare con sTable per aumentare lo spazio delle colonne
 
 *
 
 * @param string $str Stringa da allungare
 
 * @param string $num Numero di caratteri da aggiungere
 
 * @return string Restituisce la stringa allungata
 
 */
 
function str_space($str, $num){
 
    $tmp=$str;
 
    for ($i=0; $i<$num; $i++)
 
        $tmp.=' ';
 
    return $tmp;
 
}
 
?>
 
 |