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

Reply via email to