修复“Parse error: syntax error Unexpected T_STRING”错误

这类错误属于语法错误,通常是由于代码中的拼写错误引起的,例如缺少撇号、引号,缺少或多余的空格,或者注释方式不正确。

错误消息会包含有用的信息,例如发生错误的文件名和行号。要修复它,请使用 File Editor 打开该文件,转到错误消息中提到的行,并根据错误消息编辑该行,例如补全缺失的语法元素。

示例

Code editor showing PHP syntax error, unexpected '
Code editor showing PHP syntax error, unexpected '
Browser displaying a test.php page with “Hello, world!” text and the address bar visible
Browser displaying a test.php page with “Hello, world!” text and the address bar visible

从以下错误消息:

Parse error: syntax error, unexpected '<',
expecting end of file in /home/u123456789/public_html/test.php
on line 7

可以提取出以下信息:

  • 错误发生在 public_html 目录下的 test.php 文件中——这是需要编辑的文件及其位置
  • 错误发生在文件的第 7 行。File Editor 还会显示一个 ❌ 标记,当你将鼠标悬停在其上时会显示相同的错误消息:

在此文件中,PHP 代码以 。这就是为什么下一行中的 < 符号是“意外的”。

在你补全缺失的代码后,你的文件应该就能正常工作:

如果你在修复语法错误时遇到困难,可以将网站恢复到之前可用的状态

来源:Hostinger 官方帮助文档