Results 1 to 5 of 5

Thread: Mysterious Syntax Error--Well, Mysterious to Me

  1. #1
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    248
    Thanks
    88
    Thanked 3 Times in 3 Posts

    Question Mysterious Syntax Error--Well, Mysterious to Me

    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 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($argument9999);
            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.
    Last edited by marain; 05-30-2020 at 08:22 PM. Reason: Found Error

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,282
    Thanks
    97
    Thanked 104 Times in 102 Posts

    Default

    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 />;
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    248
    Thanks
    88
    Thanked 3 Times in 3 Posts

    Default

    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.

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,282
    Thanks
    97
    Thanked 104 Times in 102 Posts

    Default

    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.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. The Following User Says Thank You to james438 For This Useful Post:

    marain (05-31-2020)

  6. #5
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    248
    Thanks
    88
    Thanked 3 Times in 3 Posts

    Default

    James,

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

    Thanks for your help.

    A.

Similar Threads

  1. Our leaders dwell in mysterious places
    By molendijk in forum The lounge
    Replies: 7
    Last Post: 12-13-2012, 10:14 AM
  2. Resolved where is this mysterious padding coming from?
    By Johnnymushio in forum CSS
    Replies: 2
    Last Post: 09-29-2011, 11:25 AM
  3. Mysterious "white dots" in IE - Fade Slideshow V2
    By jgleaton in forum Dynamic Drive scripts help
    Replies: 4
    Last Post: 07-02-2011, 04:27 AM
  4. Replies: 1
    Last Post: 01-28-2011, 03:39 AM
  5. Replies: 1
    Last Post: 12-08-2009, 09:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •