Re: Re: Preferred Syntax
| From: | Robert Cummings | Date: | Thu, 15 Dec 2011 13:58:31 +0000 |
| Subject: | Re: Re: Preferred Syntax | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316026@lists.php.net to get a copy of this message | ||
On 11-12-15 02:50 AM, Ross McKay wrote:
On Wed, 14 Dec 2011 07:59:46 -0500, Rick Dwyer wrote:Heredoc and Nowdoc are nice but I hate the way they muck up my indentation aesthetics. As such when I use them I use as minimalist a terminator as possible: <?phpCan someone tell me which of the following is preferred and why? echo "<a style='text-align:left;size:14;font-weight:bold' href='/ mypage.php/$page_id'>$page_name</a><br>"; echo "<a style='text-align:left;size:14;font-weight:bold' href='/ mypage.php/".$page_id."'>".$page_name."</a><br>"; [...]Just to throw in yet another possibility: echo<<<HTML <a style="text-align:left;size:14;font-weight:bold"href="/mypage.php/$page_id">$page_name</a><br>HTML; I love HEREDOC for slabs of HTML, sometimes SQL, email bodies, etc. because they allow you to drop your variables into the output text without crufting up the formatting with string concatenation, AND they allow you to use double quotes which can be important for HTML attributes that may contain single quotes. So whilst either above option is fine for the specific context, I prefer HEREDOC when there's attributes like href. But what is "preferred" is rather dependent on the "preferrer".
echo <<<_
<a href="foo.html">Blah blah blah</a>
_;
?>
Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.