Trying to use echos commas instead of string concatenation

I don't know what I'm doing wrong here, but I get a parsing error: " Parse error: syntax error, unexpected ',' in ... "

$msg= 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; echo $msg; 

Could you help me? I do not want to use concatenation due to slower speed.

+4
source share
5 answers

Replace between the lines with . in $ msg:

 $msg= 'This is ' . htmlentities($from, ENT_QUOTES, 'UTF-8') . ' and ' . htmlentities($to, ENT_QUOTES, 'UTF-8') . ' dates statistic '; 

or echo directly:

 echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 
+2
source

Separated value based commas are arguments. You are trying to pass arguments to a variable, but not echo!

 echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'), ' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'), ' dates statistic '; 
+3
source

echo accepts several values, separated by commas, the assignment variable does not have.

which will work

 echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 

or

 $msg= 'This is '. htmlentities($from, ENT_QUOTES, 'UTF-8') . ' and ' . htmlentities($to, ENT_QUOTES, 'UTF-8') . ' dates statistic '; echo $msg; 
+2
source

You cannot use commas in line assignments; commas only work for the echo command itself. Therefore, if you want to avoid concatenation, as you mentioned above, you need to do this:

 echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'), ' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 
+2
source
 echo 'This is ', htmlentities($from, ENT_QUOTES, 'UTF-8'),' and ', htmlentities($to, ENT_QUOTES, 'UTF-8'),' dates statistic '; 

Commas only work with echo , not with variable assignment.

+1
source

Source: https://habr.com/ru/post/1369495/


All Articles