Home  >  Article  >  php教程  >  一个判断干支、属相和星座的php函数

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

PHP中文网
PHP中文网Original
2016-05-25 17:05:171716browse

一个判断干支、属相和星座的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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn