Jump to content

parse error, unexpected T_STRING


ramzess

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/16998-parse-error-unexpected-t_string/
Share on other sites

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.
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'];
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.
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... :(
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-state.edu/tutorials/section508/skipnav.htm
// more information on tabindex can be found at
// http://www.w3.org/TR/html401/interact/forms.html#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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.