Here's the code; I don't know what the problem is:

                foreach($data as $page=>$item)
                {
                        $output.= "<tr><td><a href='".$wgScript."?title=".urlencode($page)."'>";
                        // Changing this line will change the text that appears in the article link.
                        $page = str_replace("_"," ",$page);
                        $output.= $page;
                        $output.= "</a></td>\n";
                        foreach($headers as $header)
                        {
#                                $header = strtolower($header);
                                if(isset($item[$header]))
#                                        $output.= "<td>".$item[$header]."</td>\n";
                                        $output.= "<td><a href='".$wgScript."?title=".urlencode($item[$header])."'>"; //.$item[$header]."</a></td>\n";
                                        $item = str_replace("_"," ",$item); #new
//                                        $output.= /*$item[$header].*/"</a></td>\n"; #new
//		                        $output.= "</a></td>\n"; //<-------------this is the line it bitches about but it's commented out! uh...
                                else
                                        $output.= "<td>&nbsp;</td>\n";
                        }
                        $output.= "</tr>\n";
                }

    You should use {} around the if- and else-statements. If you don't the statement will only take the next row. A quick look at your code:

    if(isset($item[$header]))
        $output.= "<td><a href='".$wgScript."?title=".urlencode($item[$header])."'>"; 
    // The row above will only be run if the if-statement is true.
    $item = str_replace("_"," ",$item); #new
    // The row above will always be run
    else
    // Since there is no if-statement prior to this a else-statement can't be run.
    $output.= "<td>&nbsp;</td>\n"; 
    

      Ah, OK, thanks. Wish the error messages were more descriptive...

        Eep² wrote:

        Ah, OK, thanks. Wish the error messages were more descriptive...

        The error message is, in fact, telling you pretty much all that the parser knows for sure: it ran into an "else" token at a point in the code where one is not expected. Since it is not syntactically incorrect to have an "if" followed by one unbracketed line of code, the parser has no way of knowing if you intended the following line to be part of that if block or not, or if you meant to have an "elseif" before that second line, or just plain got everything messed up with a copy-and-paste error. So it only tells you what it knows: it ran into an "else" where it was invalid to have one.

        Yeah, perhaps the message could be a bit less cryptic; but when you get right down to it, there's not a whole lot more it could say without either guessing or reading your mind. 🙂

          This error message actually is very descriptive:

          Parse error: syntax error, unexpected T_ELSE

          The last part basically tells everything, it encountered an "else" that it didn't expect to encounter. And it probably have a row bound to it as well.

          but most of the times I agree with you, it could have been a little more descriptive.

            Just as CPUs have branch prediction, PHP (and other programming/scripting languages) could have error correction prediction where it offers up possible solutions to the problem--especially for something as "basic" as a parse error...

              "T_ELSE" is not as descriptive as "Parse error: syntax error, unexpected ELSE followed by more than 1 line of code (as designated by ending with a ";"). Be sure the "if" block/statement is surrounded by curly braces {}." Now that is descriptive! It could even give a brief example if it wanted to be even more intuitive--and even provide links to the PHP manual for the specific terminology ("parse error", "syntax error", etc). But, hey, I guess that would be too logical and intuitive, eh?

              Note the "ELSE" vs "T_ELSE" which doesn't actually appear in the code (but "else"--lowercase--does).

                Another option would be to always use curly braces when you program to avoid these problems. And never copy code without going through it row by row. That would be logical and intuitive, eh?

                Or to use google to search for an answer. That would be the logical logical thing to do, eh?

                But I have to agree with you on one thing, it could mentioned curly braces in the error, and the actual command ("else"). But you as a developer have to do some part of the work. If everything would be as descriptive as you want it more experienzed developers would grow very tired of it since they would get to much information. Somewhere the developer have to step in, and I think it is pretty good as it is.

                  I didn't create the initial code. I did use Google--that's how I ended up here. More experienced devs most likely wouldn't encounter the error nearly as much. If truly desired, a simple switch/option in the PHP settings could disable advanced/wordy/extended error messages.

                    It also gets a bit messy due to the fact that there are essentially 3 valid if/elseif/else structures. That doesn't mean that the error message couldn't be more user-friendly, but it would not just be a simple "you forgot to use braces" in all cases.

                    // only bracket multiple lines (I don't recommend this, but it's legal):
                    if(condition)
                       echo "single line command";
                    elseif(condition)
                    {
                       echo "this block has...";
                       echo "...multiple commands.";
                    }
                    else
                       echo "another single command";
                    echo "this is not part of any if/elseif/else block";
                    
                    // bracket every block:
                    if(condition)
                    {
                       echo "single line command";
                    }
                    elseif(condition)
                    {
                       echo "this block has...";
                       echo "...multiple commands.";
                    }
                    else
                    {
                       echo "another single command";
                    }
                    echo "this is not part of any if/elseif/else block";
                    
                    // alternate "colon/endif" syntax (few people use this, so not highly recommended):
                    if(condition):
                       echo "single line command";
                    elseif(condition):
                       echo "this block has...";
                       echo "...multiple commands.";
                    else:
                       echo "another single command";
                    endif;
                    echo "this is not part of any if/elseif/else block";
                    
                      Write a Reply...