$file = fopen("words.txt","r")
You need a ;
at the end of this line.
Also, since you are a beginner, you might be stop when the program says the error is on line 7 when its actually on line 4. This happens a lot when you are missing the closing semicolon ;
PHP keeps on going down your script looking for it, and when you program in actions that are surely new actions (like an if statement) PHP will throw the error, and it can only return to you the line where it stopped at, since its pretty hard to know exactly where the error is supposed to be at.