利用google实现公农历转换函数
时间:2007-08-13
来源:互联网
复制PHP内容到剪贴板
<?php
/**
* google公农历转换
* @author hemon <[email protected]>
*
* Usage:
* // 公历1983-10-5转农历
* echo lunar('1983-10-5');
* echo lunar('1983年10月05日');
* echo lunar('一九八三年十月五日');
* // 农历1983-8-29转公历
* echo lunar('1983-8-29', 1, 3);
*
* @param string 日期
* @param int 日期历法
* - 0 公历
* 1 农历
* @param int 输出格式
* - 0 农历日期
* 1 干支
* 2 属相
* 3 公历日期
* 4 星期
*
* @return string
*/
function lunar($date, $cal = 0, $format = 0){
$cals = array('%E5%85%AC%E5%8E%86','%E5%86%9C%E5%8E%86');
$pattern = '/\<table border=0 cellpadding=0 cellspacing=0>\<tr>\<td width=47 valign=middle>\<img border=0 width=40 height=30 alt="" valign=middle src="\/images\/lunar\/lunar_animal_\d+.gif">\<\/td>\<td valign=top>\<font size=-1>\<table cellspacing=0 cellpadding=2 border=0>\<tr>\<td>\<font size=-1>\S+ (.*)\<\/font>\<\/td>\<td>\<font size=-1>(.+)(.)\<\/font>\<\/td>\<\/tr>\<tr>\<td>\<font size=-1>\S+ (.*)\<\/font>\<\/td>\<td>\<font size=-1>(.*)\<br>\<\/font>\<\/td>\<\/tr>\<\/table>\<\/font>\<\/td>\<\/tr>\<\/table>/';
do {
$html = file_get_contents("http://www.google.cn/search?q={$cals[$cal]}$date");
if( $html != false ) break;
} while(true);
if(preg_match($pattern, $html, $date)){
array_shift($date);
return $date[$format];
}
return false;
}
?>
[ 本帖最后由 hemon 于 2007-8-13 10:10 编辑 ] PHP代码:
<?php
/**
* google公农历转换
* @author hemon <[email protected]>
*
* Usage:
* // 公历1983-10-5转农历
* echo lunar('1983-10-5');
* echo lunar('1983年10月05日');
* echo lunar('一九八三年十月五日');
* // 农历1983-8-29转公历
* echo lunar('1983-8-29', 1, 3);
*
* @param string 日期
* @param int 日期历法
* - 0 公历
* 1 农历
* @param int 输出格式
* - 0 农历日期
* 1 干支
* 2 属相
* 3 公历日期
* 4 星期
*
* @return string
*/
function lunar($date, $cal = 0, $format = 0){
$cals = array('%E5%85%AC%E5%8E%86','%E5%86%9C%E5%8E%86');
$pattern = '/\<table border=0 cellpadding=0 cellspacing=0>\<tr>\<td width=47 valign=middle>\<img border=0 width=40 height=30 alt="" valign=middle src="\/images\/lunar\/lunar_animal_\d+.gif">\<\/td>\<td valign=top>\<font size=-1>\<table cellspacing=0 cellpadding=2 border=0>\<tr>\<td>\<font size=-1>\S+ (.*)\<\/font>\<\/td>\<td>\<font size=-1>(.+)(.)\<\/font>\<\/td>\<\/tr>\<tr>\<td>\<font size=-1>\S+ (.*)\<\/font>\<\/td>\<td>\<font size=-1>(.*)\<br>\<\/font>\<\/td>\<\/tr>\<\/table>\<\/font>\<\/td>\<\/tr>\<\/table>/';
do {
$html = file_get_contents("http://www.google.cn/search?q={$cals[$cal]}$date");
if( $html != false ) break;
} while(true);
if(preg_match($pattern, $html, $date)){
array_shift($date);
return $date[$format];
}
return false;
}
?>
作者: hemon 发布时间: 2007-08-12
lunar()
作者: caiyuerui 发布时间: 2007-08-15
小偷..
作者: wukeyuan 发布时间: 2007-08-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28