Search code examples
phpparse-error

Parse error: syntax error, unexpected '=' in -filename- on line -linenumber-


So first, I would just like to inform you that I'm no "genius" or whatever in what I do. It might be a silly syntax error, but please, help me out here. I've been trying for hours. I really appreciate it.

So the syntax error message was

Parse error: syntax error, unexpected '=' in -filename- on line -linenumber-

just as in the title. I've marked the line number where the error occurs, so you don't have to worry about that.

  $file = fopen("blog.txt", "r");
  $dl = 1;
  $fl = 0;
  $readstr = "";
  while(! feof($file)) {
    $fileline = fgets($file);
    if ($fileline == "") {
      break;
    }
    if(dl == 1) { //heading
      echo "<h3>".$fileline."</h3>";
    }
    else if(dl == 2) { //date
      echo "Uploaded on ".$fileline."<br />";
    }
    else if(dl == 3) { //content
-->   dl = 0;
      echo $fileline;
    }
    fl++;
    dl++;
  }
  fclose($file);

I just don't get it. What's wrong in that line? dl = 0. I don't see any syntax error at all near that area.


Solution

  • As you are coding in the PHP platform, you need to maintain some convention of variable declaration. Take a deep look in you script, several time you use dl and fl without the $ sign, so you need correct them.

    Rules for PHP variables: Online Guide

    1. A variable starts with the $ sign, followed by the name of the variable
    2. A variable name must start with a letter or the underscore character
    3. A variable name cannot start with a number
    4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
    5. Variable names are case-sensitive ($age and $AGE are two different variables)