Results 1 to 6 of 6

Thread: Elusive syntax error

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

    Default Elusive syntax error

    My script doesn't work, i.e. page loads blank. I've isolated the problem to a single statement but am unable to find the syntax error. I suspect it's simple but still it eludes me. Can someone help? I've flagged the errant statement:

    PHP Code:
    <?php

    $lastUpdate 
    date"j F Y"filemtime"pageContent/quotations.txt" ) );

    $quotations = array(

    "This is quotation one",

    "&nbsp;",

    "This is quotation two.",

    "North Carolina G.S. 90-210.25(c)(9)",

    );


    $noAuthor "&nbsp;";
    $bigIndex rand(0, (count($quotations) -1)) &65534;

    echo 
    "<br /><br /><div class='quotations'> {$quotations [$bigIndex]}  <br /><br /><div align='right'>";


    // Syntax error has been isolated to the following statement

    if ({$quotations [$bigIndex 1]} != $noAuthor) {
        echo 
    "-&nbsp; {$quotations [$bigIndex 1]}";
        }

    // Error has been isolated to the preceding statement

    echo "</div></div>";

    ?>

    <center>*** Click <a href="http://www.MarainLaw.com/quotations"><span style="color : #ff4040; ">Here</span></a> for a different quote. ***</center>
    Last edited by jscheuer1; 07-27-2012 at 01:37 AM. Reason: Format

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Lose the curly brackets:

    Code:
    if ({$quotations [$bigIndex + 1]} != $noAuthor) { 
        echo "-&nbsp; {$quotations [$bigIndex + 1]}"; 
        }
    They're not valid there. Do it like so:

    Code:
    if ($quotations [$bigIndex + 1] != $noAuthor) { 
        echo "-&nbsp; {$quotations [$bigIndex + 1]}"; 
        }
    I don't pretend to know that much about PHP. But it's my understanding that the use of curly brackets in the line where they are OK:

    Code:
        echo "-&nbsp; {$quotations [$bigIndex + 1]}";
    Means roughly that, because this is a string delimited with double quotes and it might be unclear where the variables are, please resolve the data inside the curly brackets as a variable value first.

    In the line where they don't work, there are no delimiting double quotes. You could do it like so:

    Code:
    if ("{$quotations [$bigIndex + 1]}" != "$noAuthor") { 
        echo "-&nbsp; {$quotations [$bigIndex + 1]}"; 
        }
    It's just extra typing though.


    BTW, there's a typo in quotations.txt (line #612):

    "Most writers regard the truth as their most valuable ossession, and therefore are most economical in its use.",
    Should be possession.
    Last edited by jscheuer1; 07-27-2012 at 02:49 AM. Reason: add bit about the typo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    marain (07-27-2012)

  4. #3
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default Elusive Syntax Error

    Thank you. I do not feel too dumb over not having been able to solve that on my own.

    A.

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You're welcome. There were a number of other typos in that file. I was bored so I took care of all of those I could find and was certain of. I also changed the rather long Dershowitz quote at the end to proper case instead of all caps.

    If you want it I could email it as an attachment to the address on the website or to some other email address if you PM that to me. Don't put an email address in the open forum here though, it will get spammed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    marain (07-27-2012)

  7. #5
    Join Date
    Apr 2012
    Location
    Central New Jersey
    Posts
    286
    Thanks
    95
    Thanked 3 Times in 3 Posts

    Default

    It quite befuddles me how you can be bored with the time that you spend with your duties as moderator, and solving problems. Be that as it may, I would very much welcome your corrected page. The address on the web site is the one to use. The "shouting" on the Dershowitz quote I was unhappy with, but it is something I would have likely not gotten to for a long time.

    Thank you.

    A.

  8. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, sometimes I just get tired of coding. I liked the quotes. It didn't seem to take all that long. It was sort of like playing a game to wind down, something I often do.

    Anyways, I just sent it attached as quotes_spell_checked.txt
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    marain (07-28-2012)

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
  •