Thursday, January 20, 2011

[PHP] Difference betwen tow date

    public function _getDiffInHours( $date ){
        $usDate = str_replace ( "/" , "-" ,$date);
        $now = strtotime("now");
        $nextDate = strtotime ( $usDate );
        if(! is_numeric( $nextDate ) || ! is_numeric( $now ) || $nextDate <  $now ){
            return 0;
        }
        return floor( ($nextDate-$now) / (60*60));
    }

Friday, January 7, 2011

Log in other file that system.log

    public function _log($msg){
        $nameFile = 'other-file-'.date ( "Y-m-d-H" ).'.log';
        Mage::log($msg, null, $nameFile );
    }

Wednesday, January 5, 2011

Replace accented characters

    public function normaliza ($string){
        $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';   
        $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
        $string = utf8_decode($string);   
        $string = strtr($string, utf8_decode($a), $b);
        $string = strtolower($string);
        return  utf8_encode($string) ;
    }     
Powered by Blogger.