Re: Preferred Syntax

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

 



On Wed, Dec 14, 2011 at 4:59 AM, Rick Dwyer <rpdwyer@xxxxxxxxxxxxx> 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>";
>

On Wed, Dec 14, 2011 at 9:09 AM, Peter Ford <pete@xxxxxxxxxxxxx> wrote:

> Horses for courses. I use whatever I feel like at the time, and mix
> various styles, as long as it's readable!


I agree with Peter here. I would bet that the string with embedded
variables is parsed once when the file is loaded and turned into the same
bytecode as the second form.

If you are going to use the second style above, I would at least switch the
quotes around so you can use the double-quotes in the HTML as that to me
reads nicer and avoids the minor cost of scanning the string for embedded
code. I also put spaces around the dots to make the variable concatenation
easier to spot when skimming it.

    echo '<a style="text-align:left;size:**14;font-weight:bold"
href="/mypage.php/' . $page_id . '">' . $page_name . '</a><br>';

David

[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