PHP Script For Kundli Milan
PHP script for Kundli Milan (Horoscope Matching), focusing on matching by Ashtakoota Guna Milan. This script calculates compatibility based on the eight kootas: Varna, Vashya, Tara, Yoni, Graha Maitri, Gana, Bhakoot, and Nadi, with a total of 36 points.
<?php
class Goon{
function match($b,$g){
if(($b>=0 && $b<360) && ($g>=0 && $g<360) )
{
$this->b=$b;
$this->g=$g;
}
else
return false;
$this->UD =["Revati","Ashvini","Bharani","Kritika","Rohini","Mrigashira","Ardra","Punarvasu","Pushya","Ashlesha","Magha","Purva Phalguni","Uttara Phalguni","Hasta","Chitra","Swati","Vishakha","Anuradha","Jyeshtha","Mula","Purva Ashadha","Uttara Ashadha","Shravan","Dhanistha","Shatabhishaj","Purva Bhadrapad","Uttara Bhadrapad","Revati"];
$this->asRashi = ["Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpius","Sagittarius","Capricornus","Aquarius","Pisces"];
$this->swami=["Mars","Venus","Mercury","Moon","Sun","Mercury","Venus","Mars","Jupiter","Saturn","Saturn","Jupiter"];
$out=[];
$r = $this->nak();
$out[]=['Nakshtra',$r[0],$r[1],''];
$r = $this->rashi();
$out[]=['Zodiac',$r[0],$r[1],''];
$out[]=['Moon',number_format((float)$b, 2, '.', ''),number_format((float)$g, 2, '.', ''),''];
$r = $this->vran();
$out[]=['Varna',$r[1],$r[2],$r[0]];
$total = $r[0];
$r =$this->vashya();
$out[]=['Vasya',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r =$this->tara();
$out[]=['Tara',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r =$this->yoni();
$out[]=['Yoni',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r =$this->matri();
$out[]=['Matri',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r=$this->gun();
$out[]=['Gana',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r = $this->bhakoot();
$out[]=['Bhakoot',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$r =$this->naadi();
$out[]=['Nadi',$r[1],$r[2],$r[0]];
$total = $total + $r[0];
$out[]=['<b>Total</b>','','','<b>'.$total.'</b>/36'];
return $out;
}
function nak(){
$g=ceil($this->g/(800/60));
$b=ceil($this->b/(800/60));
return [$this->UD[$b].' ['.$b.']',$this->UD[$g].' ['.$g.']'];
}
function rashi(){
$g=intval($this->g/30);
$b=intval($this->b/30);
return [$this->asRashi[$b],$this->asRashi[$g]];
}
function bhakoot(){
$g=intval($this->g/30);
$b=intval($this->b/30);
$bb=fmod((12+($g))-($b),12);
$gg=fmod((12+($b))-($g),12);
$b1=fmod($bb+1,12);
$g1=fmod($gg+1,12);
if(($g1 == 2 && $b1 == 12 || $g1 == 12 && $b1 == 2) || ($g1 == 5 && $b1 == 9 || $g1 == 9 && $b1 == 5) || ($g1 == 6 && $b1 == 8 || $g1 == 8 && $b1 == 6))
$gk=0;
else
$gk=7;
return [$gk,$this->asRashi[$b],$this->asRashi[$g]];
}
function matri(){
$g=intval($this->g/30);
$b=intval($this->b/30);
$ex=[2,5,3,1,0,3,5,2,4,6,6,4];
$nadi=array(
[5,5,5,4,5,0,0],
[5,5,4,1,4,0.5,0.5],
[5,4,5,0.5,5,3,0.5],
[4,1,0.5,5,0.5,5,4],
[5,4,5,0.5,5,0.5,0.5,3],
[0,0.5,3,5,0.5,5,5],
[0,0.5,0.5,4,3,5,5]);
return [$nadi[$ex[$g]][$ex[$b]],$this->swami[$b],$this->swami[$g]];
}
function yoni(){
$g=ceil($this->g/(800/60));
$b=ceil($this->b/(800/60));
$yoni=["Horse", "Yard", "Mesh", "Snake", "Dog", "Marjar", "Mouse", "Cow", "mahish", "Tiger", "Deer", "Monkey", "nakul ","Lion"];
$yoni1=array([1,24],[2,27],[3,8],[4,5],[6,19],[7,9],[10,11],[12,26],[13,15],[14,16],[17,18],[20,22],[21,21],[23,25]);
foreach($yoni1 as $k=>$v)
{
if (in_array($g, $v))
$gg=$k;
if (in_array($b, $v))
$bb=$k;
}
$nadi=array(
[4,0,1,2,3,2,2,1,3,2,3,3,1,3],
[0,4,1,3,3,2,2,2,2,2,2,2,1,3],
[1,1,4,0,1,2,2,2,1,1,2,1,2,1],
[2,2,0,4,2,2,2,2,2,2,3,2,1,2],
[3,3,1,2,4,0,3,1,3,2,3,2,1,3],
[2,2,2,2,0,4,2,1,2,2,2,2,1,2],
[2,2,2,2,3,2,4,0,2,1,2,2,2,2],
[1,2,2,2,1,1,0,4,1,1,1,1,2,1],
[3,3,1,2,3,2,2,1,4,0,2,2,1,2],
[2,2,1,2,2,2,1,1,0,4,1,1,1,1],
[3,2,2,3,3,2,2,1,2,1,4,0,2,2],
[3,2,1,2,2,2,2,1,2,1,0,4,2,2],
[1,1,2,1,1,1,2,2,1,1,2,2,4,0],
[3,3,1,2,3,2,2,1,2,1,2,2,0,4]
);
return [$nadi[$gg][$bb],$yoni[$bb],$yoni[$gg]];
}
function tara(){
$g=ceil($this->g/(800/60));
$b=ceil($this->b/(800/60));
$na=["janm taara","sampat taara"," vipat taara","kshem taara ","pratyari taara ","saadhak taara","vadh taara","mitr taara","ati mitr taara"];
$tara=[2,4,6];
$bb=fmod((27+($g))-($b),27);
$gg=fmod((27+($b))-($g),27);
$bb=fmod($bb+1,9);
$gg=fmod($gg+1,9);
if(in_array($gg,$tara))
$g=0;
else
$g=1.5;
if(in_array($bb,$tara))
$b=0;
else
$b=1.5;
return [($b+$g),$na[$bb],$na[$gg]];
}
function vashya(){
$g=$this->g;
$b=$this->b;
$ax=["Man", "quadruped", "watering", "lion", "scorpio"];
$n[0]=array([60,90],[150,180],[180,210],[240,255],[300,330]);
$n[1]=array([0,30],[30,60],[255,270],[270,285]);
$n[2]=array([90,120],[285,300],[330,360]);
$n[3]=array();
$n[4]=array();
$bb=0;
$gg=0;
foreach($n as $k=>$v){
if(is_array($v)){
foreach($v as $kk=>$vv){
if ($g < $vv[1] && $g >= $vv[0])
$gg=$k;
if ($b < $vv[1] && $b >= $vv[0])
$bb=$k;
}
}
}
$nadi=array([2,0,0,0.5,0],[1,2,1,0.5,1],[0.5,1,2,1,1],[0,0,0,2,0],[1,1,1,0,2]);
return [$nadi[$gg][$bb],$ax[$bb],$ax[$gg]];
}
function vran(){
$g=ceil($this->g/30);
$b=ceil($this->b/30);
$ax= ["Brahmin", "Kshatriya", "Vaishya", "Shudra"];
$varn=array(array(4,8,12),array(1,5,9),array(2,6,10),array(3,7,11));
foreach($varn as $k=>$v){
if (in_array($g, $v))
$gg=$k;
if (in_array($b, $v))
$bb=$k;
}
$nadi=array([1,0,0,0],[1,1,0,0],[1,1,1,0],[1,1,1,1]);
return [$nadi[$gg][$bb],$ax[$bb],$ax[$gg]];
}
function gun(){
$g=ceil($this->g/(800/60));
$b=ceil($this->b/(800/60));
$dev=array([17,7,5,22,27,15,13,1,8],[11,20,25,12,21,26,4,2,6],[10,9,23,18,19,24,16,3,14]);
$boys=array("God" => 0, "man" => 1, "monster" => 2);
$bo=array (0 => "dev", 1 => "man", 2 => "monster");
foreach($dev as $k=>$v){
if (in_array($g, $v))
$gg=$k;
if (in_array($b, $v))
$bb=$k;
}
$gun=array(array(6,5,1),array(6,6,0),array(0,0,6));
return [$gun[$gg][$bb], $bo[$bb], $bo[$gg]];
}
function naadi(){
$g=ceil($this->g/(800/60));
$b=ceil($this->b/(800/60));
$nadi=array([1,6,7,12,13,18,19,24,25],[2,5,8,11,14,17,20,23,26],[3,4,9,10,15,16,21,22,27]);
$anadi=["Adi nadi", "middle nadi", "end nadi"];
foreach($nadi as $k=>$v){
if (in_array($g, $v))
$gg=$k;
if (in_array($b, $v))
$bb=$k;
}
if($bb == $gg)
$b=0;
else
$b= 8;
return [$b, $anadi[$bb], $anadi[$gg]];
}
}
$n=new goon;
$r=$n->match(135.79,5.89); // boy - moon Degree , girl - moon Degree
echo "<table>";
foreach($r as $k=>$v){
echo "<tr>";
foreach($v as $kk=>$vv){
echo "<td>".$vv."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
Key Features of the Script
- Ashtakoota Compatibility: Implements basic logic for Varna, Vashya, Tara, Yoni, Graha Maitri, Gana, Bhakoot, and Nadi.
- Flexible Design: Can be expanded by adding detailed calculations for each koota.
- Sample Data: Predefined Nakshatra and Rasi for boy and girl (replace with dynamic input).
- Results: Calculates the total points and determines compatibility.
METHOD -2
<?php
// Sample PHP script for Kundli Milan (Ashtakoota Guna Matching)
// Define Ashtakoota categories
$ashtakoota = [
"Varna" => 1,
"Vashya" => 2,
"Tara" => 3,
"Yoni" => 4,
"Graha Maitri" => 5,
"Gana" => 6,
"Bhakoot" => 7,
"Nadi" => 8
];
// Sample data for boy and girl (Nakshatras, Rasis, etc.)
$boyData = [
"nakshatra" => "Ashwini",
"rasi" => "Aries"
];
$girlData = [
"nakshatra" => "Rohini",
"rasi" => "Taurus"
];
// Define compatibility for each Koota
function calculateAshtakoota($boyData, $girlData) {
$compatibility = [
"Varna" => calculateVarna($boyData['rasi'], $girlData['rasi']),
"Vashya" => calculateVashya($boyData['rasi'], $girlData['rasi']),
"Tara" => calculateTara($boyData['nakshatra'], $girlData['nakshatra']),
"Yoni" => calculateYoni($boyData['nakshatra'], $girlData['nakshatra']),
"Graha Maitri" => calculateGrahaMaitri($boyData['rasi'], $girlData['rasi']),
"Gana" => calculateGana($boyData['nakshatra'], $girlData['nakshatra']),
"Bhakoot" => calculateBhakoot($boyData['rasi'], $girlData['rasi']),
"Nadi" => calculateNadi($boyData['nakshatra'], $girlData['nakshatra'])
];
return $compatibility;
}
// Sample calculation functions for each Koota
function calculateVarna($boyRasi, $girlRasi) {
// Logic for Varna matching (example logic)
$varnaRanks = ["Brahmin" => 4, "Kshatriya" => 3, "Vaishya" => 2, "Shudra" => 1];
$boyVarna = $varnaRanks["Brahmin"]; // Replace with actual mapping
$girlVarna = $varnaRanks["Vaishya"]; // Replace with actual mapping
return ($boyVarna >= $girlVarna) ? 1 : 0;
}
function calculateVashya($boyRasi, $girlRasi) {
// Logic for Vashya matching (example logic)
$vashyaPoints = [
"Aries" => ["Taurus", "Gemini"],
"Taurus" => ["Aries", "Libra"]
];
return in_array($girlRasi, $vashyaPoints[$boyRasi]) ? 2 : 0;
}
// Similar logic can be added for Tara, Yoni, Graha Maitri, Gana, Bhakoot, and Nadi
// Calculate total points
function calculateTotalPoints($compatibility) {
return array_sum($compatibility);
}
// Main Script Execution
$compatibility = calculateAshtakoota($boyData, $girlData);
$totalPoints = calculateTotalPoints($compatibility);
// Output the results
echo "Kundli Milan Results:\n";
foreach ($compatibility as $koota => $points) {
echo "$koota: $points points\n";
}
echo "Total Points: $totalPoints/36\n";
// Compatibility Result
if ($totalPoints >= 18) {
echo "Result: Compatible for Marriage!";
} else {
echo "Result: Not Compatible for Marriage!";
}
?>
How to Use This Script
- Replace the
$boyData
and$girlData
with actual inputs (e.g., from a database or user form). - Implement detailed logic for each Koota calculation based on Vedic astrology principles.
- Enhance the script with a front-end interface for user interaction.
This script serves as a foundation for building a comprehensive Kundli Milan application.