新浪星座API免費開放星座運勢 12生肖工作 愛情 理財 健康 商談 風水學 速配

來源:互聯網
上載者:User
新浪星座API免費開放星座運勢 12生肖工作 愛情 理財 健康 商談 風水學 速配

$astroDir = './';$astroArray = array (        '白羊座' => array('aries', '03/21-04/19'),        '金牛座' => array('taurus', '04/20-05/20'),        '雙子座' => array('gemini', '05/21-06/21'),        '巨蟹座' => array('cancer', '06/22-07/22'),        '獅子座' => array('leo', '07/23-08/22'),        '處女座' => array('virgo', '08/23-09/22'),        '天秤座' => array('libra', '09/23-10/23'),        '天蠍座' => array('scorpio', '10/24-11/22'),        '射手座' => array('sagittarius', '11/23-12/21'),        '魔羯座' => array('capricorn', '12/22-01/19'),        '水瓶座' => array('aquarius', '01/20-02/18'),        '雙魚座' => array('pisces', '02/19-03/20')); function generateAstro(){    global $astroDir, $astroArray;    $fileLog = $astroDir.'.log';    $log = is_file($fileLog) ? json_decode(file_get_contents($fileLog)) : false;    if(!isset($log->latestTime) || $log->latestTime < date('Y-m-d')){        foreach($astroArray as $astro){            preg_match('/(.*?)(.*?)<\/em><\/span>.*?有效日期:(.*?)綜合運勢(.*?)愛情運勢(.*?)工作狀況(.*?)理財投資(.*?)健康指數(.*?)商談指數(.*?)幸運顏色(.*?)幸運數字(.*?)速配星座(.*?)(.*?)<\/div>/isu', curl('http://vip.astro.sina.com.cn/astro/view/'.$astro[0].'/day/', $astro[0]), $matches);            file_put_contents($astroDir.$astro[0].'.dat', json_encode(array($matches[1], $matches[2], html2txt($matches[3]), substr_count($matches[4], ' html2txt($matches[3]))));        unset($matches);    }} function getAstroByDate($date){    global $astroArray;    foreach ($astroArray as $k => $v){        $value = explode('-', $v[1]);        if(date($value[0]) <= date($date) && date($date) <= date($value[1])){            return $k;        }    }    return '魔羯座';} function html2txt($document){    $search = array('@@si',  // Strip out javascript            '@<[\/\!]*?[^<>]*?>@si',            // Strip out HTML tags            '@]*?>.*?@siU',    // Strip style tags properly            '@@',         // Strip multi-line comments including CDATA            '@\s+| @'    );    $text = preg_replace($search, '', $document);    return $text;} function curl($url, $type){    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_REFERER, 'http://astro.sina.com.cn/fate/astro_'.$type.'.html?prourl=0');    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/'.mt_rand(2, 9).'.0 (Windows NT 6.1; WOW64; rv:'.mt_rand(10, 30).'.0) Gecko/'.mt_rand(2000, 2014).'0101 Firefox/'.mt_rand(10, 30).'.0');    curl_setopt($ch, CURLOPT_HEADER, 0);    $data = curl_exec($ch);    curl_close($ch);    return $data;} function isBirthDate($date){    if (empty($date) || $date == '0000-00-00')        return false;    if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))    {        return ($birth_date[1].'-'.$birth_date[2].'-'.$birth_date[3] <= date('Y-m-d'));    }    return false;}  //http://my.oschina.net/cart/var_dump(isBirthDate('2012-02-05'));//驗證生日是否真實有效var_dump(getAstroByDate('02-05'));//根據日期獲得星座名稱 generateAstro();//每天只採集1次星座資料var_dump(json_decode(file_get_contents($astroDir.'.log')));//獲得當前星座內容的時間//http://my.oschina.net/cart/
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.