PHP 中的字符串连接

Concatenation of strings in PHP

我有一个文件夹路径,我需要将其与存储在变量中的子文件夹连接起来,例如:

我有路径 somepath\theme 现在我想添加在文件夹中命名的主题,类似这样 somepath\theme\themeone 我将这个主题存储在变量中并尝试连接

$themename = 'themeone';
$path = 'somepath\theme\' . $themename;

我收到一个意外的文件结尾错误。

查看语法突出显示。您的最后一个斜杠正在转义撇号,导致您的字符串无法终止。结果你留下了一个开放的字符串。您需要转义该反斜杠。

$themename = 'themeone';
$path = 'somepath\theme\' . $themename;