我对php相当陌生。我有一个很长的字符串,我不想在其中使用换行符。在python中,我将通过执行以下操作来实现这一点:
new_string = ("string extending to edge of screen......................................."
+ "string extending to edge of screen..............................................."
+ "string extending to edge of screen..............................................."
)
我可以在 PHP 中做这样的事情吗?
您可以使用以下格式:
$string="some text...some text...some text...some text..."
."some text...some text...some text...some text...some text...";
您只需在多行中使用 concat .
运算符 - PHP 不介意新行 - 只要每个语句都以 ;
结尾。
或
$string="some text...some text...some text...some text...";
$string.="some text...some text...some text...some text...";
其中每个语句都以;
结尾,但这次我们使用与键入相同的.=
运算符:
$string="some text...some text...some text...some text...";
$string=$string."some text...some text...some text...some text...";
使用 .
运算符:
$concatened = 'string1' . 'string2';
您可以将其分布在多行中,并将其与断言运算符一起使用:
$str = 'string1';
$str .= 'string2';
...
另一种方法是使用 join()
. join()
允许使用分隔符与字符串连接和数组:
$str = join('', array(
'string1',
'string2'
));