sessions — 2013-10-02T17:16:28-04:00 — #1
I read that heredoc is for long strings of text specifically multi lines. So are we talking quantity of text or formatting?
One example I read is that someone used to use heredoc for writing out sql strings in php, so they could read the query easier.
But I write queries all the time on multiple lines without a problem, without any form of concatenating:
$sql = "SELECT
I just don't understand if heredoc is for, say, a paragraph of text, or multiple lines ( formatting wise ), that need to echo out on the page in multiple lines.
force — 2013-10-02T19:58:30-04:00 — #2
Using heredoc eliminates the need for the escaping of special characters, unlike with strings. So, if you have a large block of text or code that you want displayed somewhere without going through the trouble of escaping everything, you have that option.
ginerjm — 2013-10-02T21:57:13-04:00 — #3
heredocs is really great for writing out large blocks of html code, mixed in with some php vars. No php start/end tags, no writing echo statements with quotes and semis. Just start the heredocs block, write your html with perhaps a php var in the middle to display some dynamic content and then close the heredocs and echo that variable (that's how I do it). So much easier and much more readable!
qmonkey — 2013-10-02T22:17:13-04:00 — #4
It's a good candidate for when you have a string with many quotes. You shouldn't have to escape anything but $
$str = <<<EndMe
On the seat back of the bench on which Shelly O'riley sat was the plaque inscribed "In Loving Memory"
but she neither felt loved nor wished to have any memory of the previous forty-eight hours.
"M'am. Excuse me! M'am?" the young undertaker's assistant came calling down the lane.
Though I suppose that example could really use Nowdoc since there aren't any variables used in it.