foreach($routearr as $value)
       {
       if($value==(change here at kashmere gate ) || $value==(change here at rajiv chowk ) ||  $value==(change here at yamuna bank )   )
       {
      echo "<br>";
      echo "<div style=\"color:#8e0b0b\" > $value</div>";
        }
      else
       echo "<span style = \"color:#f80a0a\" >$value</span>";

}
in above code line 3 gives this error Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\knowdelhi\metro\metrosubmit.php on line 2009
line 2009 in the error is line three here.when i comment out this piece of code everything works ok but when i remove the above code form comments the error again creeps in so error must be in above code..but it looks ok to me...

Dani AI

Generated

A parse error reporting "unexpected T_STRING" means the PHP parser found a bare string token where it expected a different element (usually because of an unquoted string, an unclosed quote, a missing semicolon or brace, or a stray character earlier in the file). spotted the immediate cause in this thread and that fixed 's problem. The notes below show reliable ways to find similar syntax issues and a cleaner pattern to handle membership checks.

Quick debugging checklist

  • Run a syntax check from the command line to get a precise error location:
php -l path/to/file.php
  • Inspect the error line and several lines above it for missing semicolons, unclosed single/double quotes, or unmatched braces/parentheses. PHP often points to the token after the real mistake.
  • Turn on full reporting during development so you see earlier warnings that might help:
ini_set('display_errors', 1);
error_reporting(E_ALL);
  • Watch for non-ASCII characters or “smart quotes” when pasting code from editors; save as UTF-8 without BOM.
  • Use an editor with PHP syntax highlighting — it makes unclosed quotes and mismatched braces obvious.

Safer, clearer pattern for checking membership

  • Build an explicit array of allowed values and test membership. Also escape output to avoid accidental HTML injection:
$allowed = ['target1', 'target2', 'target3'];
if (in_array($value, $allowed, true)) {
    echo '<div style="color:#800">' . htmlspecialchars($value, ENT_QUOTES) . '</div>';
} else {
    echo '<span style="color:#f00">' . htmlspecialchars($value, ENT_QUOTES) . '</span>';
}

Final tips

  • If the linter still points to an odd location, strip the file down to the smallest reproducible snippet and re-add code until the error reappears. That isolates the faulty construct quickly.

Recommended Answers

All 2 Replies

if($value==(change here at kashmere gate ) || $value==(change here at rajiv chowk ) ||  $value==(change here at yamuna bank )   )

Is that your exact code? If it is, what does "change here at kashmere gate" mean? If it is supposed to be a string, enclose it in quote marks.

thanks yes the text (change here at......) is a string now its fine ....now i will keep this in mind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.