MysteryPile Developer

MP Numerology Calculator - PHP Iteration

Translate words into Destiny numbers and dates into Life numbers using an HTML web form and server-side PHP script. This version is legacy since preprocess requires a page refresh to display results from the calculator. As the first working version, the PHP code is the base for other iterations, and helpful for reference.

PHP

Numerology involves splitting multiple digit numbers and then adding them together recursively for a single digit value result. The reduceNumber function builds an array out of multiple digit numbers and adds them together. This function is bypassed if the number is already a single digit.

function reduceNumber($input) { 
	while ($input > 9 ) {
		$tempSubName = 0;
		$subNameValue = 0;
		$tempSubName = str_split($input);		
		for ($x = 0, $y = count($tempSubName); $x < $y; $x++)
			{$subNameValue = $subNameValue + $tempSubName[$x];}
		$input = $subNameValue;	
	}
return $input;
}

Variables assigned to handle error exception messaging displayed on the web page.

$errorMessageLife = "Enter numbers only.";
$errorMessageName = "Enter letters and spaces only.";

To calculate the Life number, the source value is read from the form field and validated. Any tags found in the input are removed and the number is processed to find its single digit result.

if (isset($_POST['inputLife'])) { 
	if (preg_match('/[^0-9]+/', $_POST['inputLife'], $matches))
		{ $lifeInput = 0; $lifeNumber = $errorMessageLife;}
	else { $lifeInput = $_POST['inputLife']; }

$lifeNumber = 0;
$tempLifeNumber = str_split($lifeInput);
$numberDisplay = strip_tags($lifeInput);
for ($p = 0, $q = count($tempLifeNumber); $p < $q; $p++) 
	{ $lifeNumber = $lifeNumber + $tempLifeNumber[$p]; }
$lifeNumber = reduceNumber($lifeNumber);
if ($lifeNumber == 0) { $lifeNumber = $errorMessageLife;}

Returning the Destiny number follows the similar input and validation processes as the Life Number. Phrases entered into the form are split into individual words delimited by spaces, then equated to a numerology value for each character. A result is returned by running added values through the reduceNumber function.

if (isset($_POST['inputNumber'])) { 
	if (preg_match('/[^a-zA-Z ]+/', $_POST['inputNumber'], $matches))
		{ $nameInput = 0; $destinyNumber = $errorMessageName;}
	else { $nameInput = $_POST['inputNumber']; }

inputtoArr = explode(" ", $nameInput);
$countNames = count($inputtoArr);
$nameSum = array();
$totalNameValue = array();
$nameDisplay = strip_tags($nameInput);

for($i = 0, $c = $countNames; $i < $c; $i++) {
	$currentName = $inputtoArr[$i];
	$currentNameValue = 0;
	$tempName = strtolower($currentName);
	$tempNameArr = str_split($tempName);
	for ($j = 0, $d = count($tempNameArr); $j < $d; $j++) { 
		if($tempNameArr[$j] == "a" || $tempNameArr[$j] == "j" || 
		$tempNameArr[$j] == "s") { $nameSum[$i] = $nameSum[$i] + 1; }
		if($tempNameArr[$j] == "b" || $tempNameArr[$j] == "k" || 
		$tempNameArr[$j] == "t") { $nameSum[$i] = $nameSum[$i] + 2; }
		if($tempNameArr[$j] == "c" || $tempNameArr[$j] == "l" || 
		$tempNameArr[$j] == "u") { $nameSum[$i] = $nameSum[$i] + 3; }
		if($tempNameArr[$j] == "d" || $tempNameArr[$j] == "m" || 
		$tempNameArr[$j] == "v") { $nameSum[$i] = $nameSum[$i] + 4; }
		if($tempNameArr[$j] == "e" || $tempNameArr[$j] == "n" || 
		$tempNameArr[$j] == "w") { $nameSum[$i] = $nameSum[$i] + 5; }
		if($tempNameArr[$j] == "f" || $tempNameArr[$j] == "o" || 
		$tempNameArr[$j] == "x") { $nameSum[$i] = $nameSum[$i] + 6; }
		if($tempNameArr[$j] == "g" || $tempNameArr[$j] == "p" || 
		$tempNameArr[$j] == "y") { $nameSum[$i] = $nameSum[$i] + 7; }
		if($tempNameArr[$j] == "h" || $tempNameArr[$j] == "q" || 
		$tempNameArr[$j] == "z") { $nameSum[$i] = $nameSum[$i] + 8; }
		if($tempNameArr[$j] == "i" || $tempNameArr[$j] == "r" ) 
		{ $nameSum[$i] = $nameSum[$i] + 9; }
	}
	$sumCurrentName = str_split($nameSum[$i]);
	for ($k = 0, $e = count($sumCurrentName); $k < $e; $k++) {
		$currentNameValue = $currentNameValue + $sumCurrentName[$k];
	}
	$totalNameValue[$i] = reduceNumber($currentNameValue);
}	

for ($m = 0, $g = count($totalNameValue); $m < $g; $m++) {
	$destinyNumber = $destinyNumber + $totalNameValue[$m];
}

if ($destinyNumber == 0) { $destinyNumber = $errorMessageName; }
else { $destinyNumber = reduceNumber($destinyNumber); }

HTML

Displaying results on a web page using only preprocess means pages must be reloaded to view the calculation. A form action targets an anchor tag on the page to return to the form location for display. This method can be disruptive to user experience and inflates page views in analytics software.

<span id="calc">Numerology Calculator</span>
<form name="numerologyCalculator" action="numerology.php#calc" method="post">
<p>Destiny Name: <input type="text" name="inputNumber"> 
<span class="numerologyInput"><?php echo $nameDisplay; ?></span> = 
<span class="numerologyResult"><?php echo $destinyNumber; ?></span></p>
<p>Life Date: <input type="text" action="numerology.php#calc" name="inputLife"> 
<span class="numerologyInput"><?php echo $numberDisplay; ?></span> = 
<span class="numerologyResult"><?php echo $lifeNumber; ?></span></p>
<input type="submit" name="Calculate" value="Calculate" id="calculatorButton">
</form>

Download source code - mpnc.txt

Live page - (archived)