首頁 > php教程 > PHP源码 > 主體

一个判断干支、属相和星座的php函数

PHP中文网
發布: 2016-05-25 17:05:17
原創
1755 人瀏覽過

一个判断干支、属相和星座的php函数 - 不足的是 星座应该是区分公历算的~~  有待改进

php代码

$arr = birthext ( '474768000' ); //时间戳
print_r ( $arr );
$arr = birthext ( '1985-01-17' );
print_r ( $arr );
$arr = birthext ( '19850117' );
print_r ( $arr );
登入後複製

php代码:

function birthext($birth)
{
    if (strstr ( $birth, '-' ) === false && strlen ( $birth ) !== 8)
        $birth = date ( "Y-m-d", $birth );
    if (strlen ( $birth ) === 8)
    {
        if (eregi ( '([0-9]{4})([0-9]{2})([0-9]{2})$', $birth, $bir ))
            $birth = "{$bir[1]}-{$bir[2]}-{$bir[3]}";
    }
     
    if (strlen ( $birth ) < 8)
        return false;
     
    $tmpstr = explode ( &#39;-&#39;, $birth );  
    if (count ( $tmpstr ) !== 3)
        return false;
     
    $y = ( int ) $tmpstr [0];
    $m = ( int ) $tmpstr [1];
    $d = ( int ) $tmpstr [2];
    $result = array ();
    $xzdict = array (&#39;摩羯&#39;, &#39;水瓶&#39;, &#39;双鱼&#39;, &#39;白羊&#39;, &#39;金牛&#39;, &#39;双子&#39;, &#39;巨蟹&#39;, &#39;狮子&#39;, &#39;处女&#39;, &#39;天秤&#39;, &#39;天蝎&#39;, &#39;射手&#39; );
    $zone = array (1222, 122, 222, 321, 421, 522, 622, 722, 822, 922, 1022, 1122, 1222 );
    if ((100 * $m + $d) >= $zone [0] || (100 * $m + $d) < $zone [1])
    {
        $i = 0;
    }
    else
    {
        for($i = 1; $i < 12; $i ++)
        {
            if ((100 * $m + $d) >= $zone [$i] && (100 * $m + $d) < $zone [$i + 1])
                break;
        }
    }
    $result [&#39;xz&#39;] = $xzdict [$i] . &#39;座&#39;;    
    $gzdict = array (array (&#39;甲&#39;, &#39;乙&#39;, &#39;丙&#39;, &#39;丁&#39;, &#39;戊&#39;, &#39;己&#39;, &#39;庚&#39;, &#39;辛&#39;, &#39;壬&#39;, &#39;癸&#39; ), array (&#39;子&#39;, &#39;丑&#39;, &#39;寅&#39;, &#39;卯&#39;, &#39;辰&#39;, &#39;巳&#39;, &#39;午&#39;, &#39;未&#39;, &#39;申&#39;, &#39;酉&#39;, &#39;戌&#39;, &#39;亥&#39; ) );
    $i = $y - 1900 + 36;
    $result [&#39;gz&#39;] = $gzdict [0] [($i % 10)] . $gzdict [1] [($i % 12)]; 
    $sxdict = array (&#39;鼠&#39;, &#39;牛&#39;, &#39;虎&#39;, &#39;兔&#39;, &#39;龙&#39;, &#39;蛇&#39;, &#39;马&#39;, &#39;羊&#39;, &#39;猴&#39;, &#39;鸡&#39;, &#39;狗&#39;, &#39;猪&#39; );
    $result [&#39;sx&#39;] = $sxdict [(($y - 4) % 12)];
    return $result;
}
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板