LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP parse error: unexpected { (https://www.linuxquestions.org/questions/programming-9/php-parse-error-unexpected-%7B-706880/)

li0n 02-23-2009 11:56 AM

PHP parse error: unexpected {
 
Hi,
I'm a newbie learning PHP, trying to write a dynamic menu bar. I am getting stuck on a parsing error "Parse error: syntax error, unexpected '{' in /home/karensga/public_html/Inc/KGDmenu.php on line 14". I have matching {} on all the FORs and IFs, but i must be missing something. I'm using Quanta+ 3.5.9 to write my code. Any help would be greatly appreciated.

I'm calling the file "Inc/KGDmenu.php" from my home page with

PHP Code:

<?php
$menu 
file_get_contents ('http://.../Inc/KGDmenu.php')
Echo 
$menu;
?>

The code for "Inc/KGDmenu.php" follows

PHP Code:

<?php
$mon 
= array ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$wk = array (=> '1st week',=> '2nd week',=> '3rd week',=> '4th week',=> '5th week');
$yr 2009;

for (
$m 0$m 12$m++) {
    
$max 5;        // 5 week maximum
    
$z 0;            // if $z gt 0 then add </ul> after week
    
for ($x 0$x 6$x++) {
        if (
file_exists ("../Text/".$yr."/GJ".$mon[$m].".php") && $x == 0) {
        Echo 
"<li><a href=\"/Text/".$yr."/GJ".$mon[$m].".php\">".$mon[$m]." ".substr ($yr,2,2)."</a></li>";
        }
        else {
//THE FOLLOWING LINE IS THE ONE CAUSING PROBLEMS
            
if (file_exists ("../Text/".$yr."/GJ".$mon[$m].$x.".php") {
                if (
$x $max) {
                    Echo 
"<li><a href=\"#\" class=\"parent\" >".$mon[$m]." ".substr ($yr,2,2)."</a>                <ul>";
                    
$max $x;
                }
                        
$z 1;
                        Echo 
"<li><a href=\"/Text/2009/GJ".$mon[$m].$x.".php\">".$wk[$x]."</a></li>";
            }
        }
        if (
$z !== 0) {
            Echo 
"</ul>";
            
$z 0;
        }
    }
}
?>


bgeddy 02-23-2009 12:14 PM

I'm no PHP expert but at first glance your code seems to be missing a closing ")".

Code:

//THE FOLLOWING LINE IS THE ONE CAUSING PROBLEMS
            if (file_exists ("../Text/".$yr."/GJ".$mon[$m].$x.".php") {

look like it should be :

Code:

//THE FOLLOWING LINE IS THE ONE CAUSING PROBLEMS
            if (file_exists ("../Text/".$yr."/GJ".$mon[$m].$x.".php")) {


li0n 02-23-2009 01:02 PM

Thank you. That was it. I knew I was missing something but I couldn't see it.

jlinkels 02-23-2009 02:19 PM

I recommend to use an editor which shows you matching parenthesis/braces. Quanta and Kate do automatic highlighting, joe does it with a key combination, and I assume vi and vim have that functionality as well.

jlinkels

rsciw 02-24-2009 05:12 AM

ya, vim does show it (as long as it's on the same visible page of the screen ;) not sure how it works in gvim)

as you say you're new to php (coding in general? ),
one good thing to learn from early on is good line indention, also helps a lot with
reading it and finding errors quicker (unless it's just the forums here screwing up the indentions in above php block ;)


All times are GMT -5. The time now is 12:15 AM.