On 11-12-15 02:50 AM, Ross McKay wrote:
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".

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:

<?php

    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.

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

Reply via email to