1

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.

2 Answers 2

10

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/>";
Sign up to request clarification or add additional context in comments.

3 Comments

Depending on coding style, a space is a very weak separator. Parentheses would help! echo ($i*5)."<br/>";
Ya but in such cases an space would do the job.
What if your coding style forbids the use of spaces around a dot? The more permanent solution that is also resistant against "formatting" issues is with parentheses.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.