You are here: Re: Just Learning PHP « PHP Language « IT news, forums, messages
Re: Just Learning PHP

Posted by Erwin Moller on 09/07/07 13:20

Tim Streater wrote:
> In article <1189090148.229899.215350@w3g2000hsg.googlegroups.com>,
> macca <ptmcnally@googlemail.com> wrote:
>
>>> <?php
>>> $fred = 'Click here to visit my site;
>>> echo "<a href='www.mydomain.com'>$fred</a>";
>>> ?>
>>
>>
>> Shouldnt that be :
>>
>> echo "<a href='www.mydomain.com'>{$fred}</a>";
>>
>>
>> Seriously, What's the deal with using brackets inside am
>> interpolation?
>
> I always do this:
>
> echo "<a href='www.mydomain.com'>" . $fred . "</a>";
>
> Then it's a lot clearer (to me, at any rate), due to reduced nesting.

Same here.
If the expression is complex I prefer jumping out of the string.
When it is a simple variable, I often put it in the string.
I prefer readability of code always over speed (if it matters at all).

And when you need a lot of HTML, just jump out of PHP, like:

<?php
// some db action
?>
<table>
<tr>
<td>
<?php echo $row["name"]; ?>
</td>
<td>
<?php echo $row["favcolor"]; ?>
</td>
</tr>
</table>

<?php
// back into PHP
?>


That avoids the messy echos.
But in the end, I think, it is a matter of taste.

Regards,
Erwin Moller

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация