PHP 解析错误:语法错误,CodeIgniter 视图中的文件意外结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13990681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:23:56  来源:igfitidea点击:

PHP Parse error: syntax error, unexpected end of file in a CodeIgniter View

phpcodeigniter

提问by lock

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

我正在一个unexpected end of file我笨查看错误。

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

我已将 PHP 代码粘贴到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.

这段代码通过了各种在线 PHP 语法测试,但我不知道为什么在我尝试在 WAMP 服务器中运行时它仍然显示以下错误。

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

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

作为参考,line 676是代码中的最后一行。我做错了什么?

回答by kmkaplan

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

检查您的short_open_tag设置(用于<?php phpinfo() ?>查看其当前设置)。

回答by Rudi Visser

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

Unexpected end of file意味着在 PHP 解析器到达脚本末尾之前还需要其他一些东西。

Judging from your HUGEfile, it's probably that you're missing a closing brace (}) from an ifstatement.

从您的HUGE文件来看,您可能缺少语句中的右大括号 ( }) if

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.
  1. 将代码与视图逻辑分开。
  2. 保持一致,您;在某些嵌入式 PHP 语句中使用了结尾,而不是在其他语句中,即。<?php echo base_url(); ?><?php echo $this->layouts->print_includes() ?>. 它不是必需的,所以不要使用它(或者做,只做一个或另一个)。
  3. 重复,因为它很重要,分开你的顾虑。不需要所有这些代码。
  4. 使用 IDE,它将帮助您解决诸如此类的错误。

回答by Zagor23

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

通常问题不是右方括号 (}) 或缺少分号 (;)