由于这段时间一直在做一个关于算命的小功能,需要根据输入的出生日期,来推算出生辰八字,也就是四柱(天干地枝),在Github上找到一个php写的 Calendar 类,可以根据输入的日期时间来计算出四柱(生辰八字),测试了一下完用可用。你可以在文章的未尾,找到php类文件的下载地址以及GitHub的项目地址!
php Calendar 类的使用方法
代码:<?php
$calendar=newCalendar();
//输入的阳历日期时间
$result=$calendar->solar(date('Y'),date('m'),date('d'),date('H'));
print_r($result);
?>
输出结果打印:Array
(
[lunar_year]=>
[lunar_month]=>10
[lunar_day]=>16
[lunar_hour]=>19
[lunar_year_chinese]=>二零一九
[lunar_month_chinese]=>十月
[lunar_day_chinese]=>十六
[lunar_hour_chinese]=>戌时
[ganzhi_year]=>己亥
[ganzhi_month]=>乙亥
[ganzhi_day]=>癸丑
[ganzhi_hour]=>壬戌
[wuxing_year]=>土水
[wuxing_month]=>木水
[wuxing_day]=>水土
[wuxing_hour]=>水土
[color_year]=>黄
[color_month]=>青
[color_day]=>黑
[color_hour]=>黑
[animal]=>猪
[term]=>
[is_leap]=>
[gregorian_year]=>
[gregorian_month]=>11
[gregorian_day]=>12
[gregorian_hour]=>19
[week_no]=>2
[week_name]=>星期二
[is_today]=>1
[constellation]=>天蝎
)
注:
1、输入日期时间,此类会返回一个数组
1、数组中包含:星座,生肖,五行,干枝,色彩等。
2、取数组中以‘ganzhi’为开头的元素值,组合成四柱,也就是八字
php 计算生辰八字的方法
1、php阳历(公历)日期时间转四柱(生辰八字)<?php
$calendar=newCalendar();
$result=$calendar->solar(date('Y'),date('m'),date('d'),date('H'));
echo$result['ganzhi_year'].','.$result['ganzhi_month'].','.$result['ganzhi_day'].','.$result['ganzhi_hour'];
?>
输出结果:己亥,乙亥,癸丑,壬戌
2、php阴历(农历)日期时间转四柱(生辰八字)<?php
$calendar=newCalendar();
$result=$calendar->lunar(2000,4,20,false,4);//阴历
echo$result['ganzhi_year'].','.$result['ganzhi_month'].','.$result['ganzhi_day'].','.$result['ganzhi_hour'];
?>
输出结果:庚辰,辛巳,辛巳,庚寅
注意:在使用阴历函数时,应注意输入的第四个参数为布尔存,表示输入的月分是否为润月
扩展阅读:
四柱即出生人的出生年、月、日、时分别称之为年柱、月柱、日柱和时柱;以天干地支纪年法表示出来每柱两个字,共八个字也称生辰八字,用以推算个人运程。
天干共有10个:甲、乙、丙、丁、戊、己、庚、辛、壬、癸。它们的阴阳和五行属性分别是:甲是阳木、乙阴木;丙阳火、丁阴火;戊阳土、己阴土;庚阳金、辛阴金;壬阳水、癸阴水。
地支共有12个:子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥。它们的阴阳和五行属性分别是:子是阳水,丑阴土,寅阳木,卯阴木,辰阳土,巳阴火,午阳火,未阴土,申阳金,酉阴金,戌阳土,亥阴水。
四柱八字排定之后的程序就是推命,即根据八字来推断命运,推断的内容包括大运、小运、流年、命宫、用神、星宿神煞等。
文件下载
php计算四柱(生辰八字)的类平台:所有平台|分类:编程开发|大小:0.38MB
如果觉得《八字计算方法 php php计算四柱(生辰八字)的方法》对你有帮助,请点赞、收藏,并留下你的观点哦!