PHP Code:
<?php
$lastUpdate = date( 'j F Y', filemtime( 'pageContent/test.txt' ) );
function cardinalNumber($test_number) { // TESTING TESTING TESTING
// function cardinalNumber($_SESSION["limit"] {
/*****************************************************************************************************
*
* INPUT: ZERO, OR ANY POSITIVE INTEGER UNDER 10,000
*
* RETURNS: ITS CORRESPONDING CARDINAL NUMBER
*
* REFERENCE: https://www.php.net/manual/en/langref.php
*
* REMARKS: Two ways to do this occur to me. The first way is to convert the input integer (or zero) to a string
* and then extract each digit, digit by digit, one at a time. Each extracted digit is then individually
* converted back to numeric form. We call this the "brute force" method.
*
* The second way takes the input integer and arithmetically determines each digit. This second way is
* more pedagogically challenging, more elegant, and oh, so much more fun.
*
* This function uses door two.
*
******************************************************************************************************/
// Part Zero: Definitions
$numbers = array (
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"
);
$decades = array (
"", // aughts
"", // tens
"twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
);
// Part One: Obtain argument
// $argument = min($_SESSION["limit"], 9999); // commented for testing purposes only // are you kidding me?
echo "We're now deep into the function (kinky!). Value of our test number right now is " . $test_number . ". <br /";
$argument = $test_number; // TESTING TESTING TESTING
$argument = min($argument, 9999);
echo "We're still inside the function. Value of /$argument is " . $argument . ". <br /";
echo "This is line 73. Line 72 did not print.<br />;
// Part Two: Determine place values: thousands, hundreds, tens, units
$thousands = intval($argument / 1000); // whole number of thousands
$hundreds = intval(($argument - (1000 * $thousands)) / 100); // whole number of hundreds left over
$tens = intval(($argument - ((1000 * $thousands) + (100 * $hundreds))) / 10); // whole number of tens left over
$units = $argument - (($thousands * 1000) + ($hundreds * 100) + ($tens * 10)); // residuum
//
// Part Three: Build Result
//
// Record Thousands (if any)
$result = $numbers [$thousands];
if ($thousands) {
$result = $result . " thousand";
}
// Record Hundreds (if any)
$result = $result . " " . $numbers [$hundreds];
if ($hundreds) {
$result = " " . $result . " hundred";
}
// Record Tens and Units (if any)
if ($tens > 1) {
$result = $result . " " . $decades [$tens];
if ($units) {
$result = $result . "-" . $numbers [$units];
}
}
else {
$result = $result . " " . $numbers [($tens * 10) + $units];
}
if ($argument) {
$result = "no";
}
//
// Part Four: Return Result//
//
echo "The result is " . $result; // TESTING TESTING TESTING
return; // This statement probably superfluous
}
echo "<br />";
echo "<br />";
echo "<br />";
echo "<br />";
echo "We've entered the script, not yet at function.<br />";
$test_number = 9090;
echo "We just set test number. Its present value is " . $test_number . "<br />";
echo "Now calling the function. Here we go-o-o-o-o-o-o-o-o! <br />";
cardinalNumber($test_number);
?>
<br />
<br />
<br />
<br />
Produces this message of love:
Bookmarks