Hello everybody.
I have discovered a php tool that makes things SO incredibly easy, that it isn't even funny.
I am going to type in two comparison codes that will output the same thing.
Normal code:
echo '<a href="members/members.php?id='.$id.'">'.$username.'</a><br />Click here to enter '.$username.'\'s profile.';
With the Heredoc:
echo <<<_END
<a href="members/members.php?id=$id">$username</a>
Click here to enter $username's profile.
_END;
See the difference? Yes, it is too good to be true, but I just made a heredoc a while ago, and WOW I LOVE IT!!!
Notice that I don't have to surround the HTML in quotes and I don't have to escape the ' for the possessive noun by using \.
and I don't have to append the php variables with a period on both sides. And best of all, since this combines php and HTML together, typing <br /> isn't needed to start a new line anymore! And the line break is picked up everywhere, even on textarea's. So \n isn't needed either.
Now, with this convenience comes some strict rules.
After you type <<<_END, you MUST start a new line. Or it will not work.
Then when you end it, _END must BE ON A NEW LINE BY ITSELF, this includes comments. NOTHING can be on the same line. Only the semicolon is allowed.
Well, I hope this really comes in handy for you serious web developers. It has already served me well.
Interesting blog. I've never used the HEREDOC format - although I did know it exists. I'm sure it would greatly help with the emailing scripts to keep code looking clean. I currently use a form similar to templates on the pages, which has most of the HTML written with little PHP echo snippets to drop in variables.