Multilined String in PHP

Multilined string in PHP can be written in many different ways to have your codes look clean and neat.

Method 1: You can break the lines into multiple strings on multiple lines using a period in front of the assignment sign in order to concatenate them.

Usage:
$st  = “This is the book”;
$st .= ” that I really like to read in my spare time.”;
$st .= ” I bring it with me while I’m traveling this summer.”;

Method 2: Use excerpt sign and close it at the end of all the lines. You must write exact same name as you previously defined it.

Usage:
$st = <<<STOPHERE
<p>This is the book
that I really like to read in my spare time. I bring it with me while I’m traveling this summer.</p>
STOPHERE;