$text . = '1 paragraph';
$text . = '2 paragraph';
$text . = '3 paragraph';
echo $text;
This code gives error syntax error, unexpected '='
.
What is the problem?
$text . = '1 paragraph';
$text . = '2 paragraph';
$text . = '3 paragraph';
echo $text;
This code gives error syntax error, unexpected '='
.
What is the problem?
If you are going to output all of that anyway, then why concatenate at all? Just echo it:
echo '1 paragraph',
'2 paragraph',
'3 paragraph';
I think you want:
$text = '1 paragraph';
$text .= '2 paragraph';
$text .= '3 paragraph';
echo $text;
Note that the first line does not use .=
, and just uses =
Also can echo like this
echo '1 paragraph'.'2 paragraph'.'3 paragraph';
Others have already pointed out the error: space between .
and =
.
This is a syntax/parse error. When PHP sees the .
followed by space it takes .
as a separate token which is used for string concatenation. Now it expects a string or a variable after it. But when it sees the =
it throws the parse error as it does not match the PHP grammar.