PHP - 跨越多行的字符串

PHP  - 跨越多行的字符串

问题描述:

I'm fairly new to php. I have a very long string, and I don't want to have newlines in it. In python, I would accomplish this by doing the following:

new_string = ("string extending to edge of screen......................................."
    + "string extending to edge of screen..............................................."
    + "string extending to edge of screen..............................................."
    )

Is there anything like this that I can do in PHP?

我对php很新。 我有一个非常长的字符串,我不想在其中添加换行符。 在python中,我将通过执行以下操作来完成此操作: p>

  new_string =(“字符串扩展到屏幕边缘..............  .........................“
 +”字符串延伸到屏幕边缘..............  .................................“
 +”字符串延伸到屏幕边缘......  .........................................“
)
  code  >  pre> 
 
 

我能在PHP中做这样的事吗? p> div>

You can use this format:

$string="some text...some text...some text...some text..."
."some text...some text...some text...some text...some text...";

Where you simply use the concat . operator across many lines - PHP doesn't mind new lines - as long as each statement ends with a ;.

Or

$string="some text...some text...some text...some text...";
$string.="some text...some text...some text...some text...";

Where each statement is ended with a ; but this time we use a .= operator which is the same as typing:

$string="some text...some text...some text...some text...";
$string=$string."some text...some text...some text...some text...";

Use the . operator:

$concatened = 'string1' . 'string2';

You can spread this across multiple lines and use it together with the assingment operator :

$str  = 'string1';
$str .= 'string2';

...

An alternative is to use join(). join() allows to concat and array with strings using a delimiter:

$str = join('', array(
    'string1',
    'string2'
));