Re: Embedding HTML Within a PHP Statement [message #175993 is a reply to message #175991] |
Mon, 14 November 2011 13:29 |
Erwin Moller
Messages: 228 Registered: September 2010
Karma:
|
Senior Member |
|
|
On 11/14/2011 2:07 PM, Balazs Nadasdi wrote:
> On Monday, November 14, 2011 11:10:15 AM UTC+1, Erwin Moller wrote:
>> Have you never seen constructs like these before?
>> <table>
>> <tbody>
>> <?php
>> foreach ($someDBResult as $oneRow){
>> ?>
>> <tr>
>> <td>
>> <?php echo $oneRow["firstName"]; ?>
>> </td>
>> <td>
>> <?php echo $oneRow["initials"]; ?>
>> </td>
>> </tr>
>> <?php
>> }
>> ?>
>> </tbody>
>> </table>
>
> more readable (i don't like this:<?php } ?>):
>
> <table>
> <tbody>
> <?php foreach ($someDBResult as $oneRow): ?>
> <tr>
> <td>
> <?=$oneRow["firstName"]; ?>
> </td>
> <td>
> <?=$oneRow["initials"]; ?>
> </td>
> </tr>
> <?php endforeach; ?>
> </tbody>
> </table>
Hi,
I agree it is more readable, but it also expects to have short_open_tag
set to on (or 1), which isn't always the case.
Many shared server environments this is set to off (0).
Hence, if you want to improve portability of your code, avoid those
short tags.
(Sometimes this can be overcome by using a .htaccess and override, but
that isn't always allowed either. You know: the straight-jacket shared
server.)
Of course, if you own the server and have no plans at all to ever move
your code, you can enjoy the short_open_tag. :-)
For myself, I stopped using it because of the above reasons.
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
|
|
|