Skip to main content
All CollectionsPHPPHP Advanced
How to Fix the "Unexpected T_STRING" Error
How to Fix the "Unexpected T_STRING" Error

Fixing "Parse error: syntax error Unexpected T_STRING error"

Updated over a year ago

This type of error is a syntax error, meaning it usually happens due to a typo in your code, such as a missing apostrophe, quotation mark, a missing or extra space, or code that has been commented out incorrectly.

The error message will contain useful information, such as the filename and line where it occurs. To fix it, open the file using the File Editor, go to the line mentioned in the error message, and edit the line according to the error message, such as adding any missing syntax element.

Example

From this error message:

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

The following information can be extracted:

  • The error happened in the test.php file, located in the public_html directory - this is the file that needs to be edited and its location

  • The error occurred on line 7 of the file. The File Editor will also display an ❌ sign, and the same error message if you hover over it:

A syntax error detected on File Editor including the line and description

On this file, the PHP code was opened by writing <? but it was not closed, therefore missing a ?>

This is why the < symbol in the next line is unexpected.

After you add the missing code, your file should work:

The file from the example displaying properly on a browser after fixing the syntax error

If you encounter difficulties fixing the syntax errors, you can restore your website to a previously working state.

Did this answer your question?