Log in

View Full Version : Elusive syntax error



marain
07-26-2012, 10:13 PM
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

$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>

jscheuer1
07-27-2012, 02:16 AM
Lose the curly brackets:


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

They're not valid there. Do it like so:


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:


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:


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.

marain
07-27-2012, 02:01 PM
Thank you. I do not feel too dumb over not having been able to solve that on my own.

A.

jscheuer1
07-27-2012, 03:47 PM
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.

marain
07-27-2012, 05:39 PM
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.

jscheuer1
07-28-2012, 02:42 AM
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