Re: Preferred Syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 14 Dec 2011 07:59:46 -0500, Rick Dwyer wrote:

>Can 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".
-- 
Ross McKay, Toronto NSW Australia
"All we are saying
 Is give peas a chance" - SeedSavers

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux