11
votes

I am getting an unexpected end of file error on my CodeIgniter View.

I have pasted the PHP code at http://codepad.org/S12oXE4t.

This code passed various online PHP syntax tests, but I don't know why still it shows me the below error while I was trying to run in WAMP Server.

Parse error: syntax error, unexpected end of file in
 E:\wampserver\www\CodeIgniter\application\views\layouts\default.php on line 676

For reference, line 676 is the last line in the code. What did I do wrong?

3
you missed a closing brace somewhere - Bhuvan Rikka
I tried the code, and it ran until it groused about base_url. Did you make a mistake in copying it? - RonaldBarzell
In case you encounter an error message you don't understand, it's not that wrong to pay a visit to: Reference - What does this error mean in PHP? - hakre
I checked in almost all the online tools at google.co.in/… - lock
And you have to load the url helper before using base_url() - Bhuvan Rikka

3 Answers

60
votes

Check your short_open_tag setting (use <?php phpinfo() ?> to see its current setting).

21
votes

Unexpected end of file means that something else was expected before the PHP parser reached the end of the script.

Judging from your HUGE file, it's probably that you're missing a closing brace (}) from an if statement.

Please at least attempt the following things:

  1. Separate your code from your view logic.
  2. Be consistent, you're using an end ; in some of your embedded PHP statements, and not in others, ie. <?php echo base_url(); ?> vs <?php echo $this->layouts->print_includes() ?>. It's not required, so don't use it (or do, just do one or the other).
  3. Repeated because it's important, separate your concerns. There's no need for all of this code.
  4. Use an IDE, it will help you with errors such as this going forward.
3
votes

Usually the problem is not closing brackets (}) or missing semicolon (;)