user2533777
user2533777

Reputation:

Unexpected "'String"' error (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

Today i was working with some codes when I met this error to make it simplify I have made an simple code which returns this error:

$i=1;
echo  $i*5."<br/>";

Error

syntax error, unexpected '"<br/>"' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

Here I am trying to multiply an integer variable with an integer value and then add some string afterwords. the solution I found to escape this error is to simply replace $i*5 by 5*$i but it my question is why does this happens.In my scope ov view there is no syntax error but if there is any please let me know.

Upvotes: 1

Views: 412

Answers (2)

user2930650
user2930650

Reputation:

The reason for the error is the . after 5 which makes compiler confused whether 5 is an integer or an floating value i.e it expects some digits after . but it gets "<br/>" You can add an space after the digit so that the compiler gets to know that number is over like this :

$i=1;
echo  $i*5 ."<br/>";

Upvotes: 10

Lorenz Meyer
Lorenz Meyer

Reputation: 19915

The correct syntax is either

echo  $i*5, "<br/>";
// You can echo more than one expression, separating them with comma. 

or

echo  $i*5 . "<br/>";
// Notice the space.
// 5. is interpreted as ( float ) 5

Upvotes: 0

Related Questions