Okay, a great deal of people in this forum have mentioned heredoc frome time to time, and some examples of using it have come up. I've done some reading about it, and I just have one question - what's so damn great about it?
From what I gather, it's an alternate method of echoing text, but there must be more to it if it's so popular. So, heredoc aficionados, what aren't I getting about this?
Heredoc
Moderator: General Moderators
Ahh yes, Mark is snoring away right now so I'll take my time to explain. Nevermind that part.
Anyhow, with heredoc, you won't need to escape characters, add \n for line breaks for variables, returning or printing. Usage:
With heredoc, you can also indent the code as show above. You can also use it wit return() for returning things from functions. Anyhow, at the end of the day, it's still the whole personal preference thing. I code VB-style, so I know which ends what with heredoc so I don't get parse errors everywhere.
-Nay
Anyhow, with heredoc, you won't need to escape characters, add \n for line breaks for variables, returning or printing. Usage:
Code: Select all
$var = <<< END
this
is
my
name
END;
// is equal to:
$var = "this\nis\nmy\nname";
print <<< RESULT
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>{$rows['name']}</td>
<td>{$rows['age']}</td>
</tr>
</table>
RESULT;-Nay