Log in

View Full Version : Resolved Mysterious Syntax Error--Well, Mysterious to Me



marain
05-30-2020, 08:13 PM
Folks,

Me again.

It is said that the world is divided into nurses and invalids. I'm afraid I'm an invalid--at least in PHP.

This 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:

Parse error: syntax error, unexpected 'thousand' (T_STRING), expecting ',' or ';' in /home/marainla/public_html/pageContent/test.txt on line 95

Will someone please help?

A.

james438
05-30-2020, 08:24 PM
I have not looked very closely at your script, but you appear to be missing a closing " related to this line

echo "This is line 73. Line 72 did not print.<br />;

marain
05-30-2020, 08:25 PM
Folks,

If I knew how to just delete the entire message I would.

Found error. It was in line 73, not in line 95.

Sorry for wasting your time.

A.

james438
05-30-2020, 10:39 PM
I can delete it if you want. These types of errors are not always the easiest to locate because the error message almost always points away from the source of the error.

marain
05-31-2020, 02:59 PM
James,

If you think this may help future (or present) followers, let's keep it. Otherwise no reason to.

Thanks for your help.

A.