Re: php+html mixup in displaying multidimensional array in html tables [message #176852 is a reply to message #176850] |
Sat, 28 January 2012 23:02 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma:
|
Senior Member |
|
|
.oO(Thomas 'PointedEars' Lahn)
> This is how you would write virtually unmaintainable, error-prone, slow code
> that very likely also produces invalid HTML after a few changes.
>
> Please don't.
>
> <table>
> <?php
> foreach ($arr as $line)
> {
> ?>
> <tr>
> <?php
> foreach ($line as $cell)
> {
> ?>
> <td><?php echo htmlspecialchars($cell); ?></td>
[...]
You call _that_ maintainable and readable? IBTD.
You jump in and out from PHP and even use two different indentation
styles. That's just plain ugly and error-prone, since you don't really
see which parts belong together and where a block starts and ends.
If you don't want to use many 'echo' or 'print' statements (even though
it would make perfect sense in situations like this), use some template
mechanism.
Micha
--
http://mfesser.de/blickwinkel
|
|
|