Skip to content
PHP Logo

What could be causing the "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING" in PHP code?

The "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING" in PHP code typically occurs when there is a syntax error related to a constant string. This error is commonly caused by missing quotes around a string, improper concatenation of strings, or a misplaced semicolon. To solve this issue, carefully review the code and ensure that all strings are properly enclosed in quotes and concatenated correctly.

php
// Incorrect code causing the parse error
$variable = Hello World!;

// Corrected code with quotes around the string
$variable = 'Hello World!';