0

my first post here.

I've been using php for few years, but not into it for the last couple of years.

I just started university and in a lecture yesterday there was en example looking like:

$b = "HTML";
$a = "test ", $b , "printing";
echo $a;

so the operator using to concatenate strings and variable is the comma , I've ALWAYS used the . dot. Never knew I could use the comma. I asked the lecturer and the answer was pretty vague.

Now I am researching on the manual and I found:

http://www.php.net/manual/en/language.operators.string.php

is it possible to use the , ???

jsab
  • 1

1 Answers1

0

It's . for Concatenation.

Your code should to be as,

$b = "HTML";
$a = "test" . $b . "printing";
echo $a;

Output :

testHTMLprinting

For whitespace, you should use

$b = "HTML";
$a = "test" . " " . $b . " " . "printing";
echo $a;

Output :

test HTML printing
Yuva Raj
  • 3,780
  • 1
  • 17
  • 30
  • or `$a = "test {$b} printing";` :) – message Feb 19 '14 at 10:12
  • thanks.. I always used the . but is it right that we can use the , with echo? is there any official documentation? I cannot find on the php manual – jsab Feb 20 '14 at 11:50