php php中的字符串和变量连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19954901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
String and variable concatenation in php
提问by Avoid
I am new to PHP and I want to concatenate a string with a variable without any space. I am using a variable $var
and a string which is given below.
我是 PHP 的新手,我想将一个字符串与一个没有任何空格的变量连接起来。我正在使用$var
下面给出的变量和字符串。
$var // This is variable
"Name\branch" //This is String
I want to concatenate the string and the variable without any space. I am using code like this:
我想连接字符串和变量而没有任何空格。我正在使用这样的代码:
$var2 = "Name\Branch\ $var"
But a space is created between them.
但是他们之间创造了一个空间。
回答by Glavi?
Space is there, because you entered it ;)
空间在那里,因为你输入了它;)
Use examples:
使用示例:
$var2 = "Name\Branch\$var";
$var2 = "Name\Branch\" . $var;
$var2 = 'Name\Branch\' . $var;
$var2 = "Name\Branch\{$var}";
$var2 = trim("Name\Branch\ ") . $var;
回答by Basti M
回答by Bhupendra
this will help u
这将帮助你
$var1 = 'text';
$var2 = "Name\branch\".$var1;
o/p: Name\branch\text
o/p:名称\分支\文本
回答by d_bhatnagar
You can use { } to use variable's value in a string.
您可以使用 { } 在字符串中使用变量的值。
$result = "Name\Branch\{$var}";
回答by Kevin G Flynn
Please try below code : concatenation $var and $str using dot(.)
请尝试以下代码:使用 dot(.) 连接 $var 和 $str
$var = 'variable';
$newvar = "Name\Branch\".$var
回答by vishal shah
use
用
$var2 = "Name\Branch\".$var;