当前位置:  编程技术>php
本页文章导读:
    ▪PHP阳历转农历的类      php实现的阳历转农历的类,分享给大家。 代码:   代码示例: <?php  /** * 类:阳历转农历的类 * 编辑:www. * / class Calendar{      var $everyCMonth=array(          0=>array(8,0,0,0,0,0,0.........
    ▪php实现的文件目录操作类      PHP实现的一个不错的文件与目录操作类,分享给大家。 代码:   代码示例: <?php  /**  * 文件目录操作类  * 编辑:www.  * 例子:  * $fileutil = new fileDirUtil();  * $fileutil->createDir('a.........
    ▪php获取客户端信息的类      一个php取得客户端信息的实现代码,分享给大家。 例子:   代码示例: <?php     /**    * 获取访客信息的类:语言、浏览器、操作系统、IP、地理位置、ISP。    * 日期:2013/10/11  .........

[1]PHP阳历转农历的类
    来源: 互联网  发布时间: 2013-12-24

php实现的阳历转农历的类,分享给大家。
代码:
 

代码示例:
<?php 
/**
* 类:阳历转农历的类
* 编辑:www.
* /
class Calendar{ 
    var $everyCMonth=array( 
        0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1), 
        1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2), 
        2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3), 
        3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4), 
        4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5), 
        5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6), 
        6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7), 
        7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8), 
        8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9), 
        9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10), 
        10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11), 
        11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12), 
        12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1), 
        13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2), 
        14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3), 
        15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4), 
        16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5), 
        17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6), 
        18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7), 
        19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8), 
        20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9), 
        21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10), 
        22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11), 
        23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12), 
        24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1), 
        25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2), 
        26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3), 
        27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4), 
        28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5), 
        29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6), 
        30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7), 
        31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8), 
        32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9), 
        33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10), 
        34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11), 
        35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12), 
        36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1), 
        37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2), 
        38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3), 
        39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4), 
        40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5), 
        41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6), 
        42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7), 
        43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8), 
        44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9), 
        45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10), 
        46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11), 
        47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12), 
        48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1), 
        49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2), 
        50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3), 
        51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4), 
        52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5), 
        53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6), 
        54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7), 
        55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8), 
        56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9), 
        57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10), 
        58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11), 
        59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12), 
        60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1), 
        61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2), 
        62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3), 
        63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4), 
        64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5), 
        65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6), 
        66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7), 
        67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8), 
        68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9), 
        69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10), 
        70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11), 
        71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12), 
        72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1), 
        73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2), 
        74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3), 
        75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4), 
        76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5), 
        77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6), 
        78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7), 
        79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8), 
        80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9), 
        81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10), 
        82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11), 
        83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12), 
        84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1), 
        85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2), 
        86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3), 
        87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4), 
        88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5), 
        89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6), 
        90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7), 
        91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8), 
        92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9), 
        93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10), 
        94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11), 
        95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12), 
        96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1), 
        97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2), 
        98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3), 
        99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4), 
        100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5), 
        101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6), 
        102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7), 
        103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8), 
        104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9), 
        105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10), 
        106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11), 
        107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12), 
        108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1), 
        109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2), 
        110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3), 
        111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4), 
        112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5), 
        113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6), 
        114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7), 
        115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8), 
        116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9), 
        117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10), 
        118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11), 
        119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12), 
        120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1) 
    ); 
##---------- 
    #农历天干 
    var $mten=array("null","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"); #农历地支 
    var $mtwelve=array("null","子(鼠)","丑(牛)","寅(虎)","卯(兔)","辰(龙)","巳(蛇)","午(马)","未(羊)","申(猴)","酉(鸡)","戌(狗)","亥(猪)"); #农历月份 
    var $mmonth=array("闰","正","二","三","四","五","六","七","八","九","十","十一","十二","月"); 
    var $mday=array("null","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十");#农历日 
##-----------
    #赋给初值 
    #天干地支 
    var $ten = 0; 
    var $twelve = 0; 
    function MyPub($cYear, $cMonth, $cDay){ 
        $total = 11; #阳历总天数 至1900年12月21日 
        $mtotal = 0; #阴历总天数 
        for ($y = 1901; $y < $cYear; $y++){ 
            $total += 365; 
            if ($y % 4 == 0){ 
                $total++; 
            } 
        } 
        #再加当年的几个月 
        switch ($cMonth){ 
            case 12: 
                $total += 30; 
            case 11: 
                $total += 31; 
            case 10: 
                $total += 30; 
            case 9: 
                $total += 31; 
            case 8: 
                $total += 31; 
            case 7: 
                $total += 30; 
            case 6: 
                $total += 31; 
            case 5: 
                $total += 30; 
            case 4: 
                $total += 31; 
            case 3: 
                $total += 28; 
            case 2: 
                $total += 31; 
        } 
        #如果当年是闰年还要加一天 
        if ($cYear % 4 == 0 and $cMonth > 2){ 
            $total++; 
        } 
        $total += $cDay - 1; 
        ##------------
        #用农历的天数累加来判断是否超过阳历的天数 
        for ($j = 0; $j <= 120; $j++){ 
            $i = 1; 
            for ($i = 1; $i <= 13; $i++){ 
                $mtotal += $this->everyCMonth[$j][$i]; 
                if ($mtotal >= $total){ 
                    $flag = 1; 
                    break; 
                } 
            } 
            if ($flag == 1){ 
                break; 
            } 
        } 
        return array("m" => $j, "d" => $i, "t" => $total, "n" => $mtotal); 
    } 
    function Cal($Year, $Month, $Day){ 
        $Par = $this->MyPub($Year, $Month, $Day); 
        $md = $this->everyCMonth[$Par["m"]][$Par["d"]] - ($Par["n"] - $Par["t"]); 
        $week = ($Par["t"] + 5) % 7; 
        if ($this->everyCMonth[$Par["m"]][0] <> 0 and $this->everyCMonth[$Par["m"]][0] < $Par["d"]){ 
            $mm = $Par["d"] - 1; 
        }else{ 
            $mm = $Par["d"]; 
        } 
        if ($Par["d"] == $this->everyCMonth[$Par["d"]][0] + 1 and $this->everyCMonth[$Par["d"]][0] <> 0){ 
            $cMonth = $this->mmonth[0].$this->mmonth[$mm]; #闰月 
        } 
        else{ 
            $cMonth = $this->mmonth[$mm].$this->mmonth[13]; 
        } 
        return array("year" => $this->mten[$this->everyCMonth[$Par["m"]][14]].$this->mtwelve[$this->everyCMonth[$Par["m"]][15]], "month" => $cMonth, "day" => $this->mday[$md], "week" => $week); 
    } 

 
//调用示例 
$test = new Calendar; 
$Year = $test->Cal(2004, 2, 20); 
echo $Year["year"]."年".$Year["month"].$Year["day"]."周".$Year["week"]; 
?>

    
[2]php实现的文件目录操作类
    来源: 互联网  发布时间: 2013-12-24

PHP实现的一个不错的文件与目录操作类,分享给大家。
代码:
 

代码示例:
<?php 
/**
 * 文件目录操作类
 * 编辑:www.
 * 例子:
 * $fileutil = new fileDirUtil();
 * $fileutil->createDir('a/1/2/3');                 测试建立文件夹  建一个a/1/2/3文件夹
 * $fileutil->createFile('b/1/2/3');                测试建立文件    在b/1/2/文件夹下面建一个3文件
 * $fileutil->createFile('b/1/2/3.txt');            测试建立文件    在b/1/2/文件夹下面建一个3.exe文件
 * $fileutil->writeFile('b/1/2/3.txt','this is something i write!');    在文件中写内容
 * $arr = $fileutil->readFile2array('example/mysql.txt');
 * $arr = $fileutil->readsFile('example/mysql.txt');
 * $size=$fileutil->bitSize($fileutil->getDirSize("example"));      得到文件或目录的大小
 * $fileutil->copyDir('b','d/e');                   测试复制文件夹  建立一个d/e文件夹,把b文件夹下的内容复制进去
 * $fileutil->copyFile('b/1/2/3.exe','b/b/3.exe');  测试复制文件    建立一个b/b文件夹,并把b/1/2文件夹中的3.exe文件复制进去
 * $fileutil->moveDir('a/','b/c');                  测试移动文件夹  建立一个b/c文件夹,并把a文件夹下的内容移动进去,并删除a文件夹
 * $fileutil->moveFile('b/1/2/3.exe','b/d/3.exe');  测试移动文件    建立一个b/d文件夹,并把b/1/2中的3.exe移动进去          
 * $fileutil->unlinkFile('b/d/3.exe');              测试删除文件    删除b/d/3.exe文件
 * $fileutil->unlinkDir('d');                       测试删除文件夹  删除d文件夹  
 * $list = $fileutil->dirList("E:\example");        测试列表文件夹  列出目录下所有文件
 * $list = $fileutil->dirTree("/");                 测试列表文件夹树  列出目录下所有文件直接直接的树关系
 */ 
class fileDirUtil { 
    /**
     * 建立文件夹
     *
     * @param  string $aimUrl
     * @return  viod
     */ 
    function createDir($aimUrl, $mode = 0777) { 
        $aimUrl = str_replace() ( '', '/', $aimUrl ); 
        $aimDir = ''; 
        $arr = explode() ( '/', $aimUrl ); 
        foreach ( $arr as $str ) { 
            $aimDir .= $str . '/'; 
            if (! file_exists ( $aimDir )) { 
                mkdir ( $aimDir, $mode ); 
            } 
        } 
    } 
    /**
     * 建立文件
     *
     * @param  string  $aimUrl
     * @param  boolean  $overWrite 该参数控制是否覆盖原文件
     * @return  boolean
     */ 
    function createFile($aimUrl, $overWrite = false) { 
        if (file_exists ( $aimUrl ) && $overWrite == false) { 
            return false; 
        } elseif (file_exists ( $aimUrl ) && $overWrite == true) { 
            $this->unlinkFile ( $aimUrl ); 
        } 
        $aimDir = dirname ( $aimUrl ); 
        $this->createDir ( $aimDir ); 
        touch ( $aimUrl ); 
        return true; 
    } 
    /**
     * 移动文件夹
     *
     * @param  string  $oldDir
     * @param  string  $aimDir
     * @param  boolean  $overWrite 该参数控制是否覆盖原文件
     * @return  boolean
     */ 
    function moveDir($oldDir, $aimDir, $overWrite = false) { 
        $aimDir = str_replace ( '', '/', $aimDir ); 
        $aimDir = substr ( $aimDir, - 1 ) == '/' ? $aimDir : $aimDir . '/'; 
        $oldDir = str_replace ( '', '/', $oldDir ); 
        $oldDir = substr ( $oldDir, - 1 ) == '/' ? $oldDir : $oldDir . '/'; 
        if (! is_dir ( $oldDir )) { 
            return false; 
        } 
        if (! file_exists ( $aimDir )) { 
            $this->createDir ( $aimDir ); 
        } 
        @$dirHandle = opendir ( $oldDir ); 
        if (! $dirHandle) { 
            return false; 
        } 
        while ( false !== ($file = readdir ( $dirHandle )) ) { 
            if ($file == '.' || $file == '..') { 
                continue; 
            } 
            if (! is_dir ( $oldDir . $file )) { 
                $this->moveFile ( $oldDir . $file, $aimDir . $file, $overWrite ); 
            } else { 
                $this->moveDir ( $oldDir . $file, $aimDir . $file, $overWrite ); 
            } 
        } 
        closedir ( $dirHandle ); 
        return rmdir ( $oldDir ); 
    } 
    /**
     * 移动文件
     *
     * @param  string  $fileUrl
     * @param  string  $aimUrl
     * @param  boolean  $overWrite 该参数控制是否覆盖原文件
     * @return  boolean
     */ 
    function moveFile($fileUrl, $aimUrl, $overWrite = false) { 
        if (! file_exists ( $fileUrl )) { 
            return false; 
        } 
        if (file_exists ( $aimUrl ) && $overWrite = false) { 
            return false; 
        } elseif (file_exists ( $aimUrl ) && $overWrite = true) { 
            $this->unlinkFile ( $aimUrl ); 
        } 
        $aimDir = dirname ( $aimUrl ); 
        $this->createDir ( $aimDir ); 
        rename ( $fileUrl, $aimUrl ); 
        return true; 
    } 
    /**
     * 删除文件夹
     *
     * @param  string  $aimDir
     * @return  boolean
     */ 
    function unlinkDir($aimDir) { 
        $aimDir = str_replace ( '', '/', $aimDir ); 
        $aimDir = substr ( $aimDir, - 1 ) == '/' ? $aimDir : $aimDir . '/'; 
        if (! is_dir ( $aimDir )) { 
            return false; 
        } 
        $dirHandle = opendir ( $aimDir ); 
        while ( false !== ($file = readdir ( $dirHandle )) ) { 
            if ($file == '.' || $file == '..') { 
                continue; 
            } 
            if (! is_dir ( $aimDir . $file )) { 
                $this->unlinkFile ( $aimDir . $file ); 
            } else { 
                $this->unlinkDir ( $aimDir . $file ); 
            } 
        } 
        closedir ( $dirHandle ); 
        return rmdir ( $aimDir ); 
    } 
    /**
     * 删除文件
     *
     * @param  string  $aimUrl
     * @return  boolean
     */ 
    function unlinkFile($aimUrl) { 
        if (file_exists ( $aimUrl )) { 
            unlink ( $aimUrl ); 
            return true; 
        } else { 
            return false; 
        } 
    } 
    /**
     * 复制文件夹
     *
     * @param  string  $oldDir
     * @param  string  $aimDir
     * @param  boolean  $overWrite 该参数控制是否覆盖原文件
     * @return  boolean
     */ 
    function copyDir($oldDir, $aimDir, $overWrite = false) { 
        $aimDir = str_replace ( '', '/', $aimDir ); 
        $aimDir = substr ( $aimDir, - 1 ) == '/' ? $aimDir : $aimDir . '/'; 
        $oldDir = str_replace ( '', '/', $oldDir ); 
        $oldDir = substr ( $oldDir, - 1 ) == '/' ? $oldDir : $oldDir . '/'; 
        if (! is_dir ( $oldDir )) { 
            return false; 
        } 
        if (! file_exists ( $aimDir )) { 
            $this->createDir ( $aimDir ); 
        } 
        $dirHandle = opendir ( $oldDir ); 
        while ( false !== ($file = readdir ( $dirHandle )) ) { 
            if ($file == '.' || $file == '..') { 
                continue; 
            } 
            if (! is_dir ( $oldDir . $file )) { 
                $this->copyFile ( $oldDir . $file, $aimDir . $file, $overWrite ); 
            } else { 
                $this->copyDir ( $oldDir . $file, $aimDir . $file, $overWrite ); 
            } 
        } 
        return closedir ( $dirHandle ); 
    } 
    /**
     * 复制文件
     *
     * @param  string  $fileUrl
     * @param  string  $aimUrl
     * @param  boolean  $overWrite 该参数控制是否覆盖原文件
     * @return  boolean
     */ 
    function copyFile($fileUrl, $aimUrl, $overWrite = false) { 
        if (! file_exists ( $fileUrl )) { 
            return false; 
        } 
        if (file_exists ( $aimUrl ) && $overWrite == false) { 
            return false; 
        } elseif (file_exists ( $aimUrl ) && $overWrite == true) { 
            $this->unlinkFile ( $aimUrl ); 
        } 
        $aimDir = dirname ( $aimUrl ); 
        $this->createDir ( $aimDir ); 
        copy ( $fileUrl, $aimUrl ); 
        return true; 
    } 
    /**
     * 将字符串写入文件
     *
     * @param  string  $filename 文件名
     * @param  boolean $str 待写入的字符数据
     */ 
    function writeFile($filename, $str) { 
        if (function_exists ( file_put_contents )) { 
            file_put_contents ( $filename, $str ); 
        } else { 
            $fp = fopen ( $filename, "wb" ); 
            fwrite ( $fp, $str ); 
            fclose ( $fp ); 
        } 
    } 
    /**
     * 将整个文件内容读出到一个字符串中
     *
     * @param  string  $filename 文件名
     * @return array
     */ 
    function readsFile($filename) { 
        if (function_exists ( file_get_contents )) { 
            return file_get_contents ( $filename ); 
        } else { 
            $fp = fopen ( $filename, "rb" ); 
            $str = fread ( $fp, filesize ( $filename ) ); 
            fclose ( $fp ); 
            return $str; 
        } 
    } 
    /**
     * 将文件内容读出到一个数组中
     *
     * @param  string  $filename 文件名
     * @return array
     */ 
    function readFile2array($filename) { 
        $file = file ( $filename ); 
        $arr = array (); 
        foreach ( $file as $value ) { 
            $arr [] = trim ( $value ); 
        } 
        return $arr; 
    } 
    /**
     * 转化 \ 为 /
     *
     * @param   string  $path   路径
     * @return  string  路径
     */ 
    function dirPath($path) { 
        $path = str_replace ( '\\', '/', $path ); 
        if (substr ( $path, - 1 ) != '/') 
        $path = $path . '/'; 
        return $path; 
    } 
    /**
     * 转换目录下面的所有文件编码格式
     *
     * @param   string  $in_charset     原字符集
     * @param   string  $out_charset    目标字符集
     * @param   string  $dir            目录地址
     * @param   string  $fileexts       转换的文件格式
     * @return  string  如果原字符集和目标字符集相同则返回false,否则为true
     */ 
    function dirIconv($in_charset, $out_charset, $dir, $fileexts = 'php|html|htm|shtml|shtm|js|txt|xml') { 
        if ($in_charset == $out_charset) 
        return false; 
        $list = $this->dirList ( $dir ); 
        foreach ( $list as $v ) { 
            if (preg_match ( "/\.($fileexts)/i", $v ) && is_file ( $v )) { 
                file_put_contents ( $v, iconv ( $in_charset, $out_charset, file_get_contents ( $v ) ) ); 
            } 
        } 
        return true; 
    } 
    /**
     * 列出目录下所有文件
     *
     * @param   string  $path       路径
     * @param   string  $exts       扩展名
     * @param   array   $list       增加的文件列表
     * @return  array   所有满足条件的文件
     */ 
    function dirList($path, $exts = '', $list = array()) { 
        $path = $this->dirPath ( $path ); 
        $files = glob ( $path . '*' ); 
        foreach ( $files as $v ) { 
            $fileext = $this->fileext ( $v ); 
            if (! $exts || preg_match ( "/\.($exts)/i", $v )) { 
                $list [] = $v; 
                if (is_dir ( $v )) { 
                    $list = $this->dirList ( $v, $exts, $list ); 
                } 
            } 
        } 
        return $list; 
    } 
    /**
     * 设置目录下面的所有文件的访问和修改时间
     *
     * @param   string  $path       路径
     * @param   int     $mtime      修改时间
     * @param   int     $atime      访问时间
     * @return  array   不是目录时返回false,否则返回 true
     */ 
    function dirTouch($path, $mtime = TIME, $atime = TIME) { 
        if (! is_dir ( $path )) 
        return false; 
        $path = $this->dirPath ( $path ); 
        if (! is_dir ( $path )) 
        touch ( $path, $mtime, $atime ); 
        $files = glob ( $path . '*' ); 
        foreach ( $files as $v ) { 
            is_dir ( $v ) ? $this->dirTouch ( $v, $mtime, $atime ) : touch ( $v, $mtime, $atime ); 
        } 
        return true; 
    } 
    /**
     * 目录列表
     *
     * @param   string  $dir        路径
     * @param   int     $parentid   父id
     * @param   array   $dirs       传入的目录
     * @return  array   返回目录及子目录列表
     */ 
    function dirTree($dir, $parentid = 0, $dirs = array()) { 
        global $id; 
        if ($parentid == 0) 
        $id = 0; 
        $list = glob ( $dir . '*' ); 
        foreach ( $list as $v ) { 
            if (is_dir ( $v )) { 
                $id ++; 
                $dirs [$id] = array ('id' => $id, 'parentid' => $parentid, 'name' => basename ( $v ), 'dir' => $v . '/' ); 
                $dirs = $this->dirTree ( $v . '/', $id, $dirs ); 
            } 
        } 
        return $dirs; 
    } 
    /**
     * 目录列表
     *
     * @param   string  $dir        路径
     * @return  array   返回目录列表
     */ 
    function dirNodeTree($dir) { 
        $d = dir ( $dir ); 
        $dirs = array(); 
        while ( false !== ($entry = $d->read ()) ) { 
            if ($entry != '.' and $entry != '..' and is_dir ( $dir . '/' . $entry )) { 
                $dirs[] = $entry; 
            } 
        } 
        return $dirs; 
    } 
    /**
     * 获取目录大小
     *
     * @param   string  $dirname    目录
     * @return  string    比特B
     */ 
    function getDirSize($dirname) { 
        if (! file_exists ( $dirname ) or ! is_dir ( $dirname )) 
        return false; 
        if (! $handle = opendir ( $dirname )) 
        return false; 
        $size = 0; 
        while ( false !== ($file = readdir ( $handle )) ) { 
            if ($file == "." or $file == "..") 
            continue; 
            $file = $dirname . "/" . $file; 
            if (is_dir ( $file )) { 
                $size += $this->getDirSize ( $file ); 
            } else { 
                $size += filesize ( $file ); 
            } 
 
        } 
        closedir ( $handle ); 
        return $size; 
    } 
    /**
        * 将字节转换成Kb或者Mb...
        * 参数 $size为字节大小
        */ 
    function bitSize($size) { 
        if (! preg_match ( "/^[0-9]+$/", $num )) 
        return 0; 
        $type = array ("B", "KB", "MB", "GB", "TB", "PB" ); 
 
        $j = 0; 
        while ( $num >= 1024 ) { 
            if ($j >= 5) 
            return $num . $type [$j]; 
            $num = $num / 1024; 
            $j ++; 
        } 
        return $num . $type [$j]; 
    } 
    /**
     * 获取文件名后缀
     *
     * @param   string  $filename
     * @return  string    
     */ 
    function fileext($filename) { 
        return addslashes() ( trim ( substr ( strrchr ( $filename, '.' ), 1, 10 ) ) ); 
    } 

?>

    
[3]php获取客户端信息的类
    来源: 互联网  发布时间: 2013-12-24

一个php取得客户端信息的实现代码,分享给大家。

例子:
 

代码示例:
<?php    
/**  
 * 获取访客信息的类:语言、浏览器、操作系统、IP、地理位置、ISP。  
 * 日期:2013/10/11 
 * 编辑:www.
 * 使用:  
      $obj = new class_guest_info;  
      $obj->GetLang();        //获取访客语言:简体中文、繁體中文、English。  
      $obj->GetBrowser();     //获取访客浏览器:MSIE、Firefox、Chrome、Safari、Opera、Other。  
      $obj->GetOS();          //获取访客操作系统:Windows、MAC、Linux、Unix、BSD、Other。  
      $obj->GetIP();          //获取访客IP地址。  
      $obj->GetAdd();         //获取访客地理位置,使用 Baidu 隐藏接口。  
      $obj->GetIsp();         //获取访客ISP,使用 Baidu 隐藏接口。  
 */   
class class_guest_info{    
    function GetLang() {   
        $Lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 4);    
        //使用substr()截取字符串,从 0 位开始,截取4个字符    
        if (preg_match('/zh-c/i',$Lang)) {    
        //preg_match()正则表达式匹配函数    
            $Lang = '简体中文';    
        }    
        elseif (preg_match('/zh/i',$Lang)) {    
            $Lang = '繁體中文';    
        }    
        else {    
            $Lang = 'English';    
        }    
        return $Lang;    
    }    
    function GetBrowser() {    
        $Browser = $_SERVER['HTTP_USER_AGENT'];    
        if (preg_match('/MSIE/i',$Browser)) {    
            $Browser = 'MSIE';    
        }    
        elseif (preg_match('/Firefox/i',$Browser)) {    
            $Browser = 'Firefox';    
        }    
        elseif (preg_match('/Chrome/i',$Browser)) {    
            $Browser = 'Chrome';    
        }    
        elseif (preg_match('/Safari/i',$Browser)) {    
            $Browser = 'Safari';    
        }    
        elseif (preg_match('/Opera/i',$Browser)) {    
            $Browser = 'Opera';    
        }    
        else {    
            $Browser = 'Other';    
        }    
        return $Browser;    
    }    
    function GetOS() {    
        $OS = $_SERVER['HTTP_USER_AGENT'];    
        if (preg_match('/win/i',$OS)) {    
            $OS = 'Windows';    
        }    
        elseif (preg_match('/mac/i',$OS)) {    
            $OS = 'MAC';    
        }    
        elseif (preg_match('/linux/i',$OS)) {    
            $OS = 'Linux';    
        }    
        elseif (preg_match('/unix/i',$OS)) {    
            $OS = 'Unix';    
        }    
        elseif (preg_match('/bsd/i',$OS)) {    
            $OS = 'BSD';    
        }    
        else {    
            $OS = 'Other';    
        }    
        return $OS;    
    }    
    function GetIP() {    
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {    
        //如果变量是非空或非零的值,则 empty()返回 FALSE。    
            $IP = explode()(',',$_SERVER['HTTP_CLIENT_IP']);    
        }    
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {    
            $IP = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);    
        }    
        elseif (!empty($_SERVER['REMOTE_ADDR'])) {    
            $IP = explode(',',$_SERVER['REMOTE_ADDR']);    
        }    
        else {    
            $IP[0] = 'None';    
        }    
        return $IP[0];    
    }    
    private function GetAddIsp() {    
        $IP = $this->GetIP();    
        $AddIsp = mb_convert_encoding(file_get_contents('http://open.baidu.com/ipsearch/s?tn=ipjson&wd='.$IP),'UTF-8','GBK');    
        //mb_convert_encoding() 转换字符编码。    
        if (preg_match('/noresult/i',$AddIsp)) {    
            $AddIsp = 'None';    
        }    
        else {    
            $Sta = stripos($AddIsp,$IP) + strlen($IP) + strlen('来自');    
            $Len = stripos($AddIsp,'"}')-$Sta;    
            $AddIsp = substr($AddIsp,$Sta,$Len);    
        }    
        $AddIsp = explode(' ',$AddIsp);    
        return $AddIsp;    
    }    
    function GetAdd() {    
        $Add = $this->GetAddIsp();    
        return $Add[0];    
    }    
    function GetIsp() {    
        $Isp = $this->GetAddIsp();    
        if ($Isp[0] != 'None' && isset()($Isp[1])) {    
            $Isp = $Isp[1];    
        }    
        else {    
            $Isp = 'None';    
        }    
        return $Isp;    
    }    
}    
?>

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
windows iis7站长之家
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3