LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2009, 11:56 AM   #1
li0n
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Rep: Reputation: 0
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;
        }
    }
}
?>
 
Old 02-23-2009, 12:14 PM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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")) {
 
Old 02-23-2009, 01:02 PM   #3
li0n
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you. That was it. I knew I was missing something but I couldn't see it.
 
Old 02-23-2009, 02:19 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 02-24-2009, 05:12 AM   #5
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the meaning of "PHP Parse error: parse error, unexpected $ in..." frandalla Programming 23 03-04-2009 12:34 PM
PHP Error Parse error: parse error, unexpected $ in /home/content/S/k/i/SkinCare4U/h CowanServices Programming 2 12-09-2008 08:26 PM
Parse error: parse error, unexpected $ in /home/content/d/o/m/domain/html/addpuppy2.p Scooby-Doo Programming 3 10-25-2007 09:41 AM
php send email parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expect jamesjoy Programming 7 12-06-2005 04:33 PM
PHP parse error unexpected '>' ldp Programming 2 03-04-2005 02:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration