Skip to content
PHP Logo

What common syntax errors can lead to a "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING" in PHP code?

A "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING" in PHP code typically occurs when there is a syntax error related to a constant or string within the code. This error is often caused by missing quotes, incorrect concatenation of strings, or using a constant incorrectly. To solve this issue, carefully check the syntax around the constant or string in question and ensure that it is correctly enclosed within quotes or concatenated properly.

php
// Incorrect code causing parse error
echo Hello World;

// Corrected code
echo "Hello World";