11-10-2009, 02:35 AM
Ohhh man I see those in almost every script, and everyone does it wrong.
You have 2 options to use multiline strings.
But that's bad.
Let me show you a quite better way to write multiline strings within PHP, it's called heredoc and nowdoc.
heredoc
Heredocs behave as strings inside double quotes ("), but the double quotes doesn't need to be escaped ( \" ).
The heredoc is defined with <<<, following by a indentifier and a new line.
The variables within an heredoc statement are best to be put inside of a pair of { and }
The syntax for a heredoc looks like:
Please read more
You have 2 options to use multiline strings.
PHP Code:
$str = "
Your
multiline
string ";
But that's bad.
Let me show you a quite better way to write multiline strings within PHP, it's called heredoc and nowdoc.
heredoc
Heredocs behave as strings inside double quotes ("), but the double quotes doesn't need to be escaped ( \" ).
The heredoc is defined with <<<, following by a indentifier and a new line.
http://www.php.net Wrote:Warning
It is very important to note that the line with the closing identifier must contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including Mac OS X. The closing delimiter (possibly followed by a semicolon) must also be followed by a newline.
The variables within an heredoc statement are best to be put inside of a pair of { and }
The syntax for a heredoc looks like:
PHP Code:
$str = <<<ANYTHING
You can write everything you {$want}
in as many lines as you want.
ANYTHING;
Please read more