|
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]
|