首页 > phper

PHP求天数常犯的错误详解

按N天分隔时间, 求出每一个时间段的开始和结束. 例如按7天分隔里头, 求当前时间所处的区间的开始和结束. 要注意时区!

注意, 不要简单地对时间戳取模, 而是要对时间戳与开始时间(1970-01-01)的距离进行取模.

阅读全文

shell 脚本检查某目录下php文件语法


check_php_syntax.sh

#!/bin/bash
# check php syntax
if [ $# -lt 1 ];then
    echo 'Usage: ' $0  'directory';
    exit
fi
if [ ! -d $1 ];then
    echo $1  'not a directory,please check!';
    exit
fi
directory=$1
temp_file="/tmp/file$$"
#echo $temp_file
ls -R $directory | awk  '
    BEGIN{
        FS="n"   
        folder="'$directory'"
        logname="'$temp_file'"
    }
    {
        if($0~/.php$/){
            system("php -l " folder "/" $0  "   >>  " logname  " 2>&1") 
        }
        if($0~/:$/){
            folder=substr($1,1,length($1)-1)
        }
    }
'
if [ -e $temp_file ];then
    cat $temp_file | awk '
        BEGIN{
            error = 0
       }
        {
            if($0~/Parse/) {
                error++
                errorfile[$0] = $0
            }  
        }
        END{
            print "错误文件:" error "个"
            if(length(errorfile)>0) print "错误行数:"
                for (i in errorfile)
                    print i
        }
    '
else
    echo "php file not found."
    exit;
fi

阅读全文