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?
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'
));