How can i fix 'unexpected t_encapsed_and_whitespace' in php?

Example:

echo "Hello $name! How are you today?";

This error usually arises from incorrectly embedding variables inside a double-quoted string.

Solution:

Use curly braces to embed the variable or concatenate the string.


echo "Hello {$name}! How are you today?";
// or
echo "Hello " . $name . "! How are you today?";

Beginner's Guide to PHP