Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4653 > unrolled thread
| Started by | John <John@agdp.de> |
|---|---|
| First post | 2012-01-28 12:24 +0100 |
| Last post | 2012-01-30 16:27 +0100 |
| Articles | 20 on this page of 26 — 11 participants |
Back to article view | Back to comp.lang.php
php+html mixup in displaying multidimensional array in html tables John <John@agdp.de> - 2012-01-28 12:24 +0100
Re: php+html mixup in displaying multidimensional array in html tables Luuk <Luuk@invalid.lan> - 2012-01-28 13:03 +0100
Re: php+html mixup in displaying multidimensional array in html tables crankypuss <no@email.thanks> - 2012-01-28 05:07 -0700
Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-28 19:28 +0000
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-28 15:14 -0500
Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-29 19:58 +0000
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 15:09 -0500
Re: php+html mixup in displaying multidimensional array in html tables Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-29 22:10 +0000
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 17:41 -0500
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 22:01 +0100
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-28 17:37 -0500
Re: php+html mixup in displaying multidimensional array in html tables Michael Fesser <netizen@gmx.de> - 2012-01-29 00:02 +0100
Re: php+html mixup in displaying multidimensional array in html tables The Natural Philosopher <tnp@invalid.invalid> - 2012-01-28 23:08 +0000
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 21:43 +0100
Re: php+html mixup in displaying multidimensional array in html tables "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-29 00:50 +0100
Re: php+html mixup in displaying multidimensional array in html tables r.mariotti@fdcx.net - 2012-01-29 06:55 -0500
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 15:43 +0100
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 10:44 -0500
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 17:15 +0100
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 11:45 -0500
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-29 18:41 +0100
Re: php+html mixup in displaying multidimensional array in html tables Jerry Stuckle <jstucklex@attglobal.net> - 2012-01-29 13:49 -0500
Re: php+html mixup in displaying multidimensional array in html tables Scott Johnson <noonehome@chalupasworld.com> - 2012-01-30 06:04 -0800
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-30 16:03 +0100
Re: php+html mixup in displaying multidimensional array in html tables Scott Johnson <noonehome@chalupasworld.com> - 2012-01-30 05:51 -0800
Re: php+html mixup in displaying multidimensional array in html tables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-30 16:27 +0100
Page 1 of 2 [1] 2 Next page →
| From | John <John@agdp.de> |
|---|---|
| Date | 2012-01-28 12:24 +0100 |
| Subject | php+html mixup in displaying multidimensional array in html tables |
| Message-ID | <jg0lpp$29b$1@nnrp.linuxfan.it> |
Hello, I am new to this problem and shall be very grateful for any hint on how to a´void an unreadable code-salad, when trying to display a bidimensional array (thus with two indexes) on a html table. I refer to the continuous shifting between <?php and <html> every two lines. Is there a method which is 'quick an easy' to do the job ?
[toc] | [next] | [standalone]
| From | Luuk <Luuk@invalid.lan> |
|---|---|
| Date | 2012-01-28 13:03 +0100 |
| Message-ID | <go4dv8-s9c.ln1@luuk.invalid.lan> |
| In reply to | #4653 |
On 28-01-2012 12:24, John wrote: > Hello, > > I am new to this problem and shall be very grateful for any hint on how > to a´void an unreadable code-salad, when trying to display a > bidimensional array (thus with two indexes) on a html table. > I refer to the continuous shifting between <?php and <html> every two > lines. you don't need continuous shifting ....... <?php $x=1; ?>Some <strong>html</strong> here<?php $x=$x+1 ?> Will have the same effect as: <?php $x=1; echo "Some <stong>html</strong> here"; $x=$x+1; ?> > > Is there a method which is 'quick an easy' to do the job ? > This will be a nice challenge to get to know PHP..... ;) -- Luuk
[toc] | [prev] | [next] | [standalone]
| From | crankypuss <no@email.thanks> |
|---|---|
| Date | 2012-01-28 05:07 -0700 |
| Message-ID | <jg0odo02rc@news2.newsguy.com> |
| In reply to | #4653 |
On 01/28/2012 04:24 AM, John wrote: > Hello, > > I am new to this problem and shall be very grateful for any hint on how > to a´void an unreadable code-salad, when trying to display a > bidimensional array (thus with two indexes) on a html table. > I refer to the continuous shifting between <?php and <html> every two > lines. > > Is there a method which is 'quick an easy' to do the job ? Why would you ever shift between <?php and <html>? Once you're in PHP, just stay there and do the job. Generate the whole thing. I don't see the issue, but maybe I don't understand.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2012-01-28 19:28 +0000 |
| Message-ID | <4f244c53$0$5013$a8266bb1@newsreader.readnews.com> |
| In reply to | #4653 |
On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
> I am new to this problem and shall be very grateful for any hint on how
> to a´void an unreadable code-salad, when trying to display a
> bidimensional array (thus with two indexes) on a html table. I refer to
> the continuous shifting between <?php and <html> every two lines.
>
> Is there a method which is 'quick an easy' to do the job ?
You mean something like:
echo "<table>\n";
foreach ($arr as $line) {
echo "<tr>\n";
foreach ($line as $cell) {
echo "<td>$cell</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
This is a very crude solution, makes several assumptions, and has no
testing of or handling for unexpected conditions. Depending on the data
you feed it, it may crash or generate invalid markup, but under some
conditions it might instead generate a valid table.
The wonders of usenet will probably screw the formatting too. I can't do
much about that.
Rgds
Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-28 15:14 -0500 |
| Message-ID | <jg1l00$rab$1@dont-email.me> |
| In reply to | #4659 |
On 1/28/2012 2:28 PM, Denis McMahon wrote:
> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>
>> I am new to this problem and shall be very grateful for any hint on how
>> to a´void an unreadable code-salad, when trying to display a
>> bidimensional array (thus with two indexes) on a html table. I refer to
>> the continuous shifting between<?php and<html> every two lines.
>>
>> Is there a method which is 'quick an easy' to do the job ?
>
> You mean something like:
>
> echo "<table>\n";
> foreach ($arr as $line) {
> echo "<tr>\n";
> foreach ($line as $cell) {
> echo "<td>$cell</td>\n";
> }
> echo "</tr>\n";
> }
> echo "</table>\n";
>
> This is a very crude solution, makes several assumptions, and has no
> testing of or handling for unexpected conditions. Depending on the data
> you feed it, it may crash or generate invalid markup, but under some
> conditions it might instead generate a valid table.
>
> The wonders of usenet will probably screw the formatting too. I can't do
> much about that.
>
> Rgds
>
> Denis McMahon
What is crude about it? What assumptions (other than the data does not
need to be run though htmlentities() or htmlspecialchars(), which is
quite easy to do)?
And what would crash?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2012-01-29 19:58 +0000 |
| Message-ID | <4f25a4eb$0$4921$a8266bb1@newsreader.readnews.com> |
| In reply to | #4660 |
On Sat, 28 Jan 2012 15:14:51 -0500, Jerry Stuckle wrote:
> On 1/28/2012 2:28 PM, Denis McMahon wrote:
>> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>>
>>> I am new to this problem and shall be very grateful for any hint on
>>> how to a´void an unreadable code-salad, when trying to display a
>>> bidimensional array (thus with two indexes) on a html table. I refer
>>> to the continuous shifting between<?php and<html> every two lines.
>>>
>>> Is there a method which is 'quick an easy' to do the job ?
>>
>> You mean something like:
>>
>> echo "<table>\n";
>> foreach ($arr as $line) {
>> echo "<tr>\n";
>> foreach ($line as $cell) {
>> echo "<td>$cell</td>\n";
>> }
>> echo "</tr>\n";
>> }
>> echo "</table>\n";
>>
>> This is a very crude solution, makes several assumptions, and has no
>> testing of or handling for unexpected conditions. Depending on the data
>> you feed it, it may crash or generate invalid markup, but under some
>> conditions it might instead generate a valid table.
>>
>> The wonders of usenet will probably screw the formatting too. I can't
>> do much about that.
> What is crude about it? What assumptions (other than the data does not
> need to be run though htmlentities() or htmlspecialchars(), which is
> quite easy to do)?
1) If the sub arrays don't all contain the same number of elements, you
could get a table with different numbers of cells in different rows.
Ideally you ought to catch that somehow. One of the principles I was
taught was about being liberal in what you accept as input and specific
in what you generate as output.
2) What if an array member is a binary object or a class?
Ultimately my solution is probably only suited to 2d arrays containing
the same number of elements in each sub-array, and where each element in
a sub-array is either an html safe string or a numeric value.
> And what would crash?
I have no idea what it will do if you feed it a binary object or a class
as a sub-array element, but I suspect it may crash. Whatever it does do,
from the point of view that the desired behaviour is that of "generating
meaningful html", I doubt it would work as desired if eg
$arr[3][2] = imagecreatetruecolor(640,480);
$arr[1][3] = fopen("/path/file.type","r");
etc etc
Rgds
Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-29 15:09 -0500 |
| Message-ID | <jg4929$ov7$1@dont-email.me> |
| In reply to | #4678 |
On 1/29/2012 2:58 PM, Denis McMahon wrote:
> On Sat, 28 Jan 2012 15:14:51 -0500, Jerry Stuckle wrote:
>
>> On 1/28/2012 2:28 PM, Denis McMahon wrote:
>>> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>>>
>>>> I am new to this problem and shall be very grateful for any hint on
>>>> how to a´void an unreadable code-salad, when trying to display a
>>>> bidimensional array (thus with two indexes) on a html table. I refer
>>>> to the continuous shifting between<?php and<html> every two lines.
>>>>
>>>> Is there a method which is 'quick an easy' to do the job ?
>>>
>>> You mean something like:
>>>
>>> echo "<table>\n";
>>> foreach ($arr as $line) {
>>> echo "<tr>\n";
>>> foreach ($line as $cell) {
>>> echo "<td>$cell</td>\n";
>>> }
>>> echo "</tr>\n";
>>> }
>>> echo "</table>\n";
>>>
>>> This is a very crude solution, makes several assumptions, and has no
>>> testing of or handling for unexpected conditions. Depending on the data
>>> you feed it, it may crash or generate invalid markup, but under some
>>> conditions it might instead generate a valid table.
>>>
>>> The wonders of usenet will probably screw the formatting too. I can't
>>> do much about that.
>
>> What is crude about it? What assumptions (other than the data does not
>> need to be run though htmlentities() or htmlspecialchars(), which is
>> quite easy to do)?
>
> 1) If the sub arrays don't all contain the same number of elements, you
> could get a table with different numbers of cells in different rows.
> Ideally you ought to catch that somehow. One of the principles I was
> taught was about being liberal in what you accept as input and specific
> in what you generate as output.
>
This is from a MySQL query - multiple rows, all with the same number of
columns.
> 2) What if an array member is a binary object or a class?
>
See above.
> Ultimately my solution is probably only suited to 2d arrays containing
> the same number of elements in each sub-array, and where each element in
> a sub-array is either an html safe string or a numeric value.
>
See above.
>> And what would crash?
>
> I have no idea what it will do if you feed it a binary object or a class
> as a sub-array element, but I suspect it may crash. Whatever it does do,
> from the point of view that the desired behaviour is that of "generating
> meaningful html", I doubt it would work as desired if eg
>
See above.
> $arr[3][2] = imagecreatetruecolor(640,480);
> $arr[1][3] = fopen("/path/file.type","r");
>
> etc etc
>
> Rgds
>
> Denis McMahon
Read the entire post. None of your arguments are valid.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2012-01-29 22:10 +0000 |
| Message-ID | <4f25c3ba$0$5059$a8266bb1@newsreader.readnews.com> |
| In reply to | #4679 |
On Sun, 29 Jan 2012 15:09:41 -0500, Jerry Stuckle wrote: > This is from a MySQL query - multiple rows, all with the same number of > columns. I must have missed where the OP said that. >> 2) What if an array member is a binary object or a class? > See above. > Read the entire post. None of your arguments are valid. I checked the OP's post - it says nothing about the array being populated from a MySql query. In addition, even if it was populated from a MySql query, I don't know if any of the columns in the table(s) concerned are BLOBs. I did wonder if the "John Drako <jbravo556@gmail.removethis.com>" in the "Fast/Easy way to extract a column from multi-dimensional array?" thread was also the John "<John@agdp.de>" in this thread, but wasn't actually assuming that he was. Rgds Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-29 17:41 -0500 |
| Message-ID | <jg4hug$llv$1@dont-email.me> |
| In reply to | #4680 |
On 1/29/2012 5:10 PM, Denis McMahon wrote: > On Sun, 29 Jan 2012 15:09:41 -0500, Jerry Stuckle wrote: > >> This is from a MySQL query - multiple rows, all with the same number of >> columns. > > I must have missed where the OP said that. > >>> 2) What if an array member is a binary object or a class? > >> See above. > >> Read the entire post. None of your arguments are valid. > > I checked the OP's post - it says nothing about the array being populated > from a MySql query. > > In addition, even if it was populated from a MySql query, I don't know if > any of the columns in the table(s) concerned are BLOBs. > > I did wonder if the "John Drako<jbravo556@gmail.removethis.com>" in the > "Fast/Easy way to extract a column from multi-dimensional array?" thread > was also the John "<John@agdp.de>" in this thread, but wasn't actually > assuming that he was. > > Rgds > > Denis McMahon If any of the data were BLOBs, he would know it. He's also responsible for putting data into the database. Completely immaterial in this case. As for the array - he should also know the contents of the array and the number of elements in each array. Your comments are only valid if he had nothing to do with building the array or its contents. Which he also didn't say. The time to validate stuff is when it's being put into the array, and validating the array as it is built. Then you don't have to worry about complicated and hard-to-maintain code like you are suggesting. The bottom line is - start with good data and coding is easy. Build crap data and the code becomes much harder to understand and maintain (needless to say adding a lot more bugs to the scripts). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-01-28 22:01 +0100 |
| Message-ID | <5865552.bgypaU67uL@PointedEars.de> |
| In reply to | #4659 |
Denis McMahon wrote:
> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>> I am new to this problem and shall be very grateful for any hint on how
>> to a´void an unreadable code-salad, when trying to display a
>> bidimensional array (thus with two indexes) on a html table. I refer to
>> the continuous shifting between <?php and <html> every two lines.
>>
>> Is there a method which is 'quick an easy' to do the job ?
>
> You mean something like:
>
> echo "<table>\n";
> foreach ($arr as $line) {
> echo "<tr>\n";
> foreach ($line as $cell) {
> echo "<td>$cell</td>\n";
> }
> echo "</tr>\n";
> }
> echo "</table>\n";
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>
<?php
}
?>
</tr>
<?php
}
?>
</table>
is just fine (see how the braces and tags align at different columns?).
There is also a more verbose alternative syntax, which you could write as
follows:
<table>
<?php foreach ($arr as $line): ?>
<tr>
<?php foreach ($line as $cell): ?>
<td><?php echo htmlspecialchars($cell); ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>
But currently that does not work well with Eclipse PDT:
<https://bugs.eclipse.org/bugs/show_bug.cgi?id=359473>
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-28 17:37 -0500 |
| Message-ID | <jg1tai$bpv$1@dont-email.me> |
| In reply to | #4663 |
On 1/28/2012 4:01 PM, Thomas 'PointedEars' Lahn wrote:
> Denis McMahon wrote:
>
>> On Sat, 28 Jan 2012 12:24:14 +0100, John wrote:
>>> I am new to this problem and shall be very grateful for any hint on how
>>> to a´void an unreadable code-salad, when trying to display a
>>> bidimensional array (thus with two indexes) on a html table. I refer to
>>> the continuous shifting between<?php and<html> every two lines.
>>>
>>> Is there a method which is 'quick an easy' to do the job ?
>>
>> You mean something like:
>>
>> echo "<table>\n";
>> foreach ($arr as $line) {
>> echo "<tr>\n";
>> foreach ($line as $cell) {
>> echo "<td>$cell</td>\n";
>> }
>> echo "</tr>\n";
>> }
>> echo "</table>\n";
>
> 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>
> <?php
> }
> ?>
> </tr>
> <?php
> }
> ?>
> </table>
>
> is just fine (see how the braces and tags align at different columns?).
> There is also a more verbose alternative syntax, which you could write as
> follows:
>
> <table>
> <?php foreach ($arr as $line): ?>
> <tr>
> <?php foreach ($line as $cell): ?>
> <td><?php echo htmlspecialchars($cell); ?></td>
> <?php endforeach; ?>
> </tr>
> <?php endforeach; ?>
> </table>
>
> But currently that does not work well with Eclipse PDT:
>
> <https://bugs.eclipse.org/bugs/show_bug.cgi?id=359473>
>
>
> PointedEars
This is a perfect example of the original op's question. No way would I
keep going in and out of PHP like that. Other than the missing call to
htmlspecialchars(), I find Denis's code much more readable and maintainable.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | Michael Fesser <netizen@gmx.de> |
|---|---|
| Date | 2012-01-29 00:02 +0100 |
| Message-ID | <f7v8i7htpcjh7i41q83e5gtou0kn4g0sdh@mfesser.de> |
| In reply to | #4663 |
.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
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2012-01-28 23:08 +0000 |
| Message-ID | <jg1v5h$eas$3@news.albasani.net> |
| In reply to | #4665 |
Michael Fesser wrote:
> .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.
>
I assume he was demonstrating the exact opposite actually.
"This is how you would write virtually unmaintainable, error-prone, slow
code that very likely also produces invalid HTML after a few changes."
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-01-28 21:43 +0100 |
| Message-ID | <1412482.V9SEqChMir@PointedEars.de> |
| In reply to | #4653 |
John wrote: > I am new to this problem and shall be very grateful for any hint on how > to a´void an unreadable code-salad, when trying to display a > bidimensional array (thus with two indexes) on a html table. > I refer to the continuous shifting between <?php and <html> every two > lines. You mean `<?php' and `?>'; there can be only one `<html>' tag in a (Valid) HTML document. Contrary to common misconception, several `<?php's and `?>'s in a file parsed by PHP are healthy and appropriate, as it is the most efficient method (stdin --> stdout) and the easiest to maintain (no quoting necessary; parsing, that includes syntax highlighting and client-side validation, just works both for HTML and PHP). Only make sure that you do not mix too much program logic with the output (loops are OK). Use the template approach (not necessarily a full-blown template system like Smarty). And, as always, indent your code so that you can tell sections apart. RTFM: <http://www.php.net/manual/en/tutorial.firstpage.php> > Is there a method which is 'quick an easy' to do the job ? Yes. You have found it. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-01-29 00:50 +0100 |
| Message-ID | <9ojfv3Fhu4U1@mid.uni-berlin.de> |
| In reply to | #4653 |
Am 28.01.2012 12:24, schrieb John: > Hello, > > I am new to this problem and shall be very grateful for any hint on how to a´void an > unreadable code-salad, when trying to display a bidimensional array (thus with two > indexes) on a html table. > I refer to the continuous shifting between <?php and <html> every two lines. > > Is there a method which is 'quick an easy' to do the job ? > Quick and easy? Easy is what you know. I am at times still shocked to see how popular CMSs written in PHP mix up HTML and PHP. This is generally unmaintainable, un-designable. For quick, go with the echo style proposed. For the heavier lifting use a template system, once you know it it will be very easy. This will help you separate code / application logic, and design. Template systems produce in the end scripts with a mix of PHP and HTML, but this is not the level you work on. And you can give your templates to a designer. I am quite happy with Smarty 3. /Str.
[toc] | [prev] | [next] | [standalone]
| From | r.mariotti@fdcx.net |
|---|---|
| Date | 2012-01-29 06:55 -0500 |
| Message-ID | <cccai75tko4ojjcrtoaefs6bpnehvfnng9@4ax.com> |
| In reply to | #4668 |
After developing numerus commercial sites over the past decade+ all the php I've created is by far mostly procedural. I personally never leave php and output my pages with a "print <<<EOD" and the entire page follows, variaables embededded and all. Easy to create, read, follow, maintain, etc. Just over a year ago I inherited a large Drupal site with over 10K pages. Talk about dropping in/out of code... this site will do so 4,6,8 times per LINE. Its not only hard to follow the logic but even harder to find the html one might be looking for. And to me the killer is when they use things like this: <?php "}"?> to end a logic block. Try and find those on a large page. Do the drop in/out techniques work? Of course. But so does poorly structured english written sentences. But they're almost impossible to read. Just my $.02 1/2 cents on this topic.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-01-29 15:43 +0100 |
| Message-ID | <5854644.bgypaU67uL@PointedEars.de> |
| In reply to | #4670 |
r.mariotti@fdcx.net wrote: > After developing numerus commercial sites over the past decade+ all > the php I've created is by far mostly procedural. I personally never > leave php and output my pages with a "print <<<EOD" and the entire > page follows, variaables embededded and all. > Easy to create, read, follow, maintain, etc. Except when you want to indent or client-side validate your code. As for the former, the EOD (or whatever delimiter you use) must be at the *beginning of the line* and must at most followed by `;'. As for the latter, a client-side HTML validator will not see the HTML that you put out because to it it is PHP. In addition, you still would have string escaping issues and difficulties with function calls, and it is very inefficient to have PHP string-parse large chunks of code that does not need parsing in the first place. <http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc> BTDT. Here-doc is tempting as a solution to this problem, but in the long run it is more trouble than it is worth. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-29 10:44 -0500 |
| Message-ID | <jg3pgj$of1$1@dont-email.me> |
| In reply to | #4671 |
On 1/29/2012 9:43 AM, Thomas 'PointedEars' Lahn wrote: > r.mariotti@fdcx.net wrote: > >> After developing numerus commercial sites over the past decade+ all >> the php I've created is by far mostly procedural. I personally never >> leave php and output my pages with a "print<<<EOD" and the entire >> page follows, variaables embededded and all. >> Easy to create, read, follow, maintain, etc. > > Except when you want to indent or client-side validate your code. As for > the former, the EOD (or whatever delimiter you use) must be at the > *beginning of the line* and must at most followed by `;'. As for the > latter, a client-side HTML validator will not see the HTML that you put out > because to it it is PHP. > What does indenting have to do with it? And an HTML validator will definitely see ALL the HTML you put out - because it is sent to the client. > In addition, you still would have string escaping issues and difficulties > with function calls, and it is very inefficient to have PHP string-parse > large chunks of code that does not need parsing in the first place. > What parsing is being done, other than the entire file, which the PHP interpreter has to do anyway? All PHP is doing is outputting the strings. > <http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc> > > BTDT. Here-doc is tempting as a solution to this problem, but in the long > run it is more trouble than it is worth. > That's your opinion. I've found it quite useful in many instances. It clarifies the code, making it much easier to understand and maintain. > > PointedEars But then these are typical comments from you. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-01-29 17:15 +0100 |
| Message-ID | <5359343.2Cvizievi3@PointedEars.de> |
| In reply to | #4672 |
Jerry Stuckle wrote: > On 1/29/2012 9:43 AM, Thomas 'PointedEars' Lahn wrote: >> r.mariotti@fdcx.net wrote: >>> After developing numerus commercial sites over the past decade+ all >>> the php I've created is by far mostly procedural. I personally never >>> leave php and output my pages with a "print<<<EOD" and the entire >>> page follows, variaables embededded and all. >>> Easy to create, read, follow, maintain, etc. >> >> Except when you want to indent or client-side validate your code. As for >> the former, the EOD (or whatever delimiter you use) must be at the >> *beginning of the line* and must at most followed by `;'. As for the >> latter, a client-side HTML validator will not see the HTML that you put >> out because to it it is PHP. > > What does indenting have to do with it? And an HTML validator will > definitely see ALL the HTML you put out - because it is sent to the > client. You can't read, can you? PointedEars -- Sometimes, what you learn is wrong. If those wrong ideas are close to the root of the knowledge tree you build on a particular subject, pruning the bad branches can sometimes cause the whole tree to collapse. -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-01-29 11:45 -0500 |
| Message-ID | <jg3t45$cor$1@dont-email.me> |
| In reply to | #4673 |
On 1/29/2012 11:15 AM, Thomas 'PointedEars' Lahn wrote: > Jerry Stuckle wrote: > >> On 1/29/2012 9:43 AM, Thomas 'PointedEars' Lahn wrote: >>> r.mariotti@fdcx.net wrote: >>>> After developing numerus commercial sites over the past decade+ all >>>> the php I've created is by far mostly procedural. I personally never >>>> leave php and output my pages with a "print<<<EOD" and the entire >>>> page follows, variaables embededded and all. >>>> Easy to create, read, follow, maintain, etc. >>> >>> Except when you want to indent or client-side validate your code. As for >>> the former, the EOD (or whatever delimiter you use) must be at the >>> *beginning of the line* and must at most followed by `;'. As for the >>> latter, a client-side HTML validator will not see the HTML that you put >>> out because to it it is PHP. >> >> What does indenting have to do with it? And an HTML validator will >> definitely see ALL the HTML you put out - because it is sent to the >> client. > > You can't read, can you? > > > PointedEars A whole lot better than you, obviously. But then you one again have shown you have no idea what you're talking about. But then you ignore valid arguments and just take pot shots at anyone who points out you are wrong. You are well-known for this in multiple newsgroups. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.php
csiph-web