Jump to content


Photo

parse error, unexpected T_STRING


  • Please log in to reply
13 replies to this topic

#1 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 10:47 AM

Greetings guys!
I'm stuck with it just because I simply don't know PHP. Learning.
I took this code from karlcore.com (thanks to it's author), I followed the instructions, bet all I get is:

Parse error: parse error, unexpected T_STRING in C:\Program Files\TSW\Apache2\htdocs\EIC\menu1.php on line 3

I am working and testing this under Windows XP.

Here is the code:

<?php
$nav_options = array(
"Home" => "/index.php",
"Blog" => "/blog/index.php", 
"News" => "/news/index.php",
"Resume" => "/resume/index.php",
"Past Work" => "/portfolio/index.php",
"Articles" => "/articles/index.php",
"Downloads" => "/programming/index.php",
"Links" => "/links/index.php"
);

$current_url = $_SERVER['index1.php']; 

print("<!-- begin menu include -->
<div id=\"navigation\">\n 
<ul id=\"navigation\">\n");

$tabindex = 2;


foreach($nav_options as $key => $val){

if($val != $current_url){
print("<li><a href=\"$val\" tabindex=\"$tabindex\">$key</a> </li>");
$tabindex++;
}
else{
print("<li class=\"curr_loc\">$key</li>");
}


print("</ul>");
print("</div><!-- end menu include -->");
?>

As I checked the forum prior the posting my problem in here, it seemed that most common
problem in this case is missing semicolumn. Well here I can't see them missing. :(

Thank you guys in advance.

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 09 August 2006 - 10:52 AM

I cant see any problems except the fact there's no such thing as $_SERVER['index1.php']...

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 09 August 2006 - 10:56 AM

Well i get the error on line 25 which is this line:
print("<li><a href=\"$val\" tabindex=\"$tabindex\">$key[/url] </li>");

It is due to the fact there is no space between $key and [/url]. Therefore, php thinks that $key is an array and thinkgs /url is an element of that array. Put a space between them and it should work.

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 09 August 2006 - 11:02 AM

Try changing this line to:
print('<li><a href="'.$val.'" tabindex="'.$tabindex.'">'.$key.'</ a></li>');

(Just notice I wrote "</ a>" because the forum changes it to BBcode tags, so remove the space inside the tag).

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 11:27 AM

Well unfortunately it gives me the same error. Now I even placed original, unchanged PHP script but it does not work.
Complains about the same thing.

It is so bad I don't know how to make my own script yet... all I want is a vertical menu included in every page on my site
where menu itself resides in a single file, so if I might change something in future, I don't need to change through every single
file. And that is what I know how to make very well. Reason I am messing with this code is that I would like the menu
item (link) become styled by CSS when the page it points to is currently open. By styling I mean changing background color of
the active item. And this wonderful code from http://karlcore.com/programming/dynav/ seemed to be the best solution, but
now I am desperate. :(


Re $_SERVER['index1.php']
originally there was

// define our current location
$current_url = $_SERVER['PHP_SELF'];

#6 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 12:58 PM

Or maybe, if there is another way out of this problem (not using this script) you guys could help me with that.
I don't know what to do. Thank you.

#7 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 09 August 2006 - 01:02 PM

Is the error still showing up on line 3 for you?

#8 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 01:06 PM

Yes.. unfortunately... :(

maybe there is some problem in php configuration (php.ini) or maybe this code I took from the address above, (where everything is explained in comments on how to make it work), is not supposed to be working on Windows system?

#9 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 09 August 2006 - 01:09 PM

Well that i dont understand. With your original code i get an error on line 25. I cant figure out what could possibly cause an error in creating that array, whatever your ini settings are. I am also using windows XP anyway.

The only thing i can think is that perhaps in the code in your editor, there is a character that is not showing perhaps. Try copying the original code you pasted back into notepad and save it as a php file. Then try it again.

#10 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 01:10 PM

Here is a good example of what I am trying to achieve: http://www.asma.org/
this is how I am trying to make my navigation panel work...
I know how to make it work like that putting this control panel contents in every single page of my site,
but what I want to do is to put it in only one file and then to be called in by php... :(

#11 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 01:15 PM

Ok I will try...

#12 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 01:25 PM

Wow... that is just great, you guys are great. Thanks GingerRobot!
I did copy it from the site, step by step, excluding comments and everything, and it works now!
well... not the way I want, but at least it generates the contents of menu and does not give me this error.

now I got to unbderstand what this

// define our current location
$current_url = $_SERVER['PHP_SELF'];

and

// tabindex is set to "2" here, because my "skiplink" is set as "1"
// more information on a skiplink can be found at
// http://www.wac.ohio-...508/skipnav.htm
// more information on tabindex can be found at
// http://www.w3.org/TR...l#adef-tabindex
$tabindex = 2;

does. should I leave this PHP_SELF as it is, or I must change it to something?
and tabindex? does it indexes my menu items for when I use TAB key on kyeboard?

#13 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 August 2006 - 01:46 PM

should I leave this PHP_SELF as it is, or I must change it to something?
and tabindex? does it indexes my menu items for when I use TAB key on kyeboard?


Yes. Yes.
Legend has it that reading the manual never killed anyone.
My site

#14 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 09 August 2006 - 01:49 PM

Well thank you very much for being so welcome and helpful.
I believe for you it is nothing for me it is my first try in PHP and making my own website! Thank you!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users