PHP中的字符串和变量串联 [英] String and variable concatenation in php

查看:66
本文介绍了PHP中的字符串和变量串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP的新手,我想用不带空格的变量将字符串连接起来。我正在使用变量 $ var 和下面给出的字符串。

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.

$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.

推荐答案

存在空格,因为您输入了空格;)

Space is there, because you entered it ;)

使用示例:

$var2 = "Name\Branch\\$var";
$var2 = "Name\Branch\\" . $var;
$var2 = 'Name\Branch\\' . $var;
$var2 = "Name\Branch\\{$var}";
$var2 = trim("Name\Branch\ ") . $var;

这篇关于PHP中的字符串和变量串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆