PHP 年龄计算函数(精确到天)

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
/**
* PHP 年龄计算函数
*
* 参数支持数组传参和标准的 Mysql date 类型传参
* params sample
* --------------------------------------------------
$birthArr = array(
'year' => '2000',
'month' => '11',
'day' => '3'
);
$birthStr = '2000-11-03';
* --------------------------------------------------
* );
* @author IT不倒翁 <itbudaoweng@gmail.com>
* @copyright (c) 2011,2012 Just Use It!
* @link IT不倒翁 http://yungbo.com
* @param string|array $birthday
* @return number $age
*/
function getAge($birthday) {
$age = 0;
$year = $month = $day = 0;
if (is_array($birthday)) {
extract($birthday);
} else {
if (strpos($birthday, '-') !== false) {
list($year, $month, $day) = explode('-', $birthday);
$day = substr($day, 0, 2); //get the first two chars in case of '2000-11-03 12:12:00'
}
}
$age = date('Y') - $year;
if (date('m') < $month || (date('m') == $month && date('d') < $day)) $age--;
return $age;
}

相关文章

简单采集了yahoo的一些数据

以前在公司就写过类似的东西,这次是帮以前的上司写了一个简单的采集程序。    很简单的。。汗。没什么技术含量的。    数据来源:http://c...

PHP无刷新上传文件实现代码

index.html 复制代码 代码如下: <html> <head> <title>无刷新上传文件</title> <meta C...

php与python实现的线程池多线程爬虫功能示例

本文实例讲述了php与python实现的线程池多线程爬虫功能。分享给大家供大家参考,具体如下: 多线程爬虫可以用于抓取内容了这个可以提升性能了,这里我们来看php与python 线程池多...

PHP实现的AES加密、解密封装类与用法示例

本文实例讲述了PHP实现的AES加密、解密封装类与用法。分享给大家供大家参考,具体如下: <?php /** * Class AES * 用于AES加解密数据 *...

php图片上传存储源码并且可以预览

复制代码 代码如下: <?php header("content-Type: text/html; charset=gb2312"); $uptypes=array('image/...