如何在PHP中连接字符串?

问题描述:

I have three strings:

$str1 = "abc"; $str2 = "def"; $str3 = "ghi";

I can get the value of all of them like this:

echo "$str1$str2$str3";

But I heard there is a way to join them together, so I can echo all of them without quotes.

我有三个字符串: p>

$ str1 =“abc”; \ n $ str2 =“def”; $ str3 =“ghi”; p>

我可以像这样得到所有这些值: p>

echo“$ str1 $ str2 $ str3”; p>

但我听说有一种方法可以将它们连接在一起,所以我可以不用引号回显它们。 p> DIV>

You're looking for string concantation.

It's

echo $str1 . $str2 . $str3;

See http://nz2.php.net/language.operators.string for more information.

How about:

echo $str1 . $str2 . $str3;

As well as concatenating like this

echo $str1 . $str2 . $str3;

You can also just output them in sequence, which avoids evaluating an intermediate string

echo $str1 , $str2 , $str3;

Finally, you can use braces in string to disambiguate string replacement:

echo "{$str1}{$str2}{$str3}";