function signFromHangul($str) { //$hanguls = call_user_func_array('array_merge', linearHangul($str)); $hanguls = linearHangul($str); $hangulToStrokes = ["ㄱ" => 1, "ㄲ" => 2, "ㄴ" => 1, "ㄷ" => 2, "ㄸ" => 4, "ㄹ" => 3, "ㅁ" => 3, "ㅂ" => 4, "ㅃ" => 8, "ㅅ" => 2, "ㅆ" => 4, "ㅇ" => 1, "ㅈ" => 3, "ㅉ" => 6, "ㅊ" => 4, "ㅋ" => 2, "ㅌ" => 3, "ㅍ" => 4, "ㅎ" => 3, "ㅏ" => 2, "ㅐ" => 3, "ㅑ" => 3, "ㅒ" => 4, "ㅓ" => 2, "ㅔ" => 3, "ㅕ" => 3, "ㅖ" => 4, "ㅗ" => 2, "ㅘ" => 4, "ㅙ" => 5, "ㅚ" => 3, "ㅛ" => 3, "ㅜ" => 2, "ㅝ" => 4, "ㅞ" => 5, "ㅟ" => 3, "ㅠ" => 3, "ㅡ" => 1, "ㅢ" => 2, "ㅣ" => 1, "" => 0, "ㄳ" => 3, "ㄵ" => 4, "ㄶ" => 5, "ㄺ" => 4, "ㄻ" => 6, "ㄼ" => 7, "ㄽ" => 5, "ㄾ" => 6, "ㄿ" => 7, "ㅀ" => 7, "ㅄ" => 6]; $strokes = 0; foreach ($hanguls as $hangul) { $strokes += $hangulToStrokes[$hangul]; } return $strokes % 2 != 0; }
function birthYearExplanation($bday, $name, $gender) { $bdaySign = signFromBday($bday); $elementName = startElementFromBday($bday); $linearName = linearHangul($name, True); //print_r($linearName); $explanations = []; $steps = ["ITSELF", "PREV", "POINTEDBY", "POINT", "NEXT"]; foreach ($steps as $step) { $element = elementGetObj($elementName, $step); //print_r($element->hangul); $hangulCandidates = $element->hangul; // If there's no explanation for this hangul if (count(array_intersect($hangulCandidates, $linearName)) == 0) { $msg = explanation($step, $gender, NULL, NULL, NULL, True); array_push($explanations, $msg); continue; } foreach ($hangulCandidates as $value) { for ($i = 0; $i < count($linearName); $i++) { if ($linearName[$i] == $value) { //echo " > step: $step value: $value nameChar: $nameChar "; $nameChar = hangulAtIndex($name, $i); $nameSign = signFromHangul($nameChar); //echo "nameSign: $nameSign"; $isGood = isGoodExplanation($linearName, $i, $element); $msg = explanation($step, $gender, $bdaySign, $nameSign, $isGood); //echo "msg: $msg"; //print_r($msg); array_push($explanations, $msg); } } } } return $explanations; }