Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - String spanning multiple lines

Tags:

string

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?

like image 424
SheerSt Avatar asked Nov 04 '13 22:11

SheerSt


People also ask

What is EOD PHP?

EOD = End Of Data, EOT = End of Text.

How do you escape an apostrophe in PHP?

If you want to render the \' sequence, you must use three backslashes ( \\\' ). First \\ to render the backslash itself, and then \' to render the apostrophe.

How strings are declared in PHP explain string operators?

We can create a string in PHP by enclosing the text in a single-quote. It is the easiest way to specify string in PHP. For specifying a literal single quote, escape it with a backslash (\) and to specify a literal backslash (\) use double backslash (\\).


1 Answers

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...";
like image 62
Fluffeh Avatar answered Oct 16 '22 15:10

Fluffeh