473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

indenting

Dear readers,

If you use some funtion to generate html code like:

<?
function display_stuff( parameters)
{
echo "<p>\n";
echo " <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"
width=\"100%\">\n";
/* .. more stuff here... */
echo " </table>\n";
echo "</p>\n";
}
?>

Is there some way to know your 'current horizontal position' so you can
indent a html section properly?

Tia, Jean
Jan 4 '06 #1
5 1810
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jean Pion wrote:
Is there some way to know your 'current horizontal position' so you can
indent a html section properly?


Ugh.

You may want to use Output Buffering along with the Tidy functions.
http://php.net/manual/en/ref.outcontrol.php
http://php.net/manual/en/ref.tidy.php

(And - indenting HTML code is not as important as making clean,
standards-compliant, valid HTML code).

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_*************************@hotmail.com
Jabber:iv*********@jabber.org ; iv*********@kdetalk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDu/bY3jcQ2mg3Pc8RAn+dAJ9nKfBduWiHByebT4SBBh+o6vQgBQCf c5cD
8j+DvfHPubYwhvUbgJAdjJc=
=9zBL
-----END PGP SIGNATURE-----
Jan 4 '06 #2
Jean Pion wrote:
Dear readers,

If you use some funtion to generate html code like:

<?
function display_stuff( parameters)
{
echo "<p>\n";
echo " <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"
width=\"100%\">\n";
/* .. more stuff here... */
echo " </table>\n";
echo "</p>\n";
}
?>

Is there some way to know your 'current horizontal position' so you can
indent a html section properly?

Tia, Jean

As Iván alludes to, the great thing about php is you're really writing a
program, not html. So, in the php commands you'll want neat code. That
will benefit you when you go back to it. I would recommend also
including comments about what is going on, so you don't have to try to
remember 6 months from now. But the only reason to generate neat html
is so the users can look at the page source and make sense of it more.

Tom
Jan 4 '06 #3
Jean Pion wrote:
Is there some way to know your 'current horizontal position' so you can
indent a html section properly?


When I care about indentation (which is not very often), I tend to achieve
it by passing an $indent parameter to the function, which takes a string
of whitespace and prepends it to each line.

Example follows...

================================================

<?php

function createDiv ($innerText, $indent='')
{
$innerText = str_replace("\n", "\n{$indent} ", $innerText);
return "{$indent}<div>\n"
. "{$indent} {$innerText}\n"
. "{$indent}</div>";
}

$divInner = createDiv("Hello world");
$divMiddle = createDiv($divInner);
$divOuter = createDiv($divMiddle, ' ');

?>
<html>
<body>
<?= $divOuter ?>

</body>
</html>

================================================

Which should generate:

<html>
<body>
<div>
<div>
<div>
Hello
</div>
</div>
</div>
</body>
</html>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 4 '06 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

tomb wrote:
But the only reason to generate neat html
is so the users can look at the page source and make sense of it more.


Besides, a developer should not read raw HTML, but should have a look at the
DOM tree - there are wonderful DOM tree inspectors for Konqueror and
Firefox (built-in) and for IE (via third-party toolbars).

Analyzing the DOM tree generated by the PHP scripts, and validating the
generated HTML against W3C's validators would prove more useful than
writing scripts that generate indented HTML.

(In fact, my programs generate a gibberish of (X)HTML that validates quite
nicely, but is a mess to read).

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
5.0.5-3 generating this signature.
Uptime: 02:03:19 up 1 day, 4:28, 1 user, load average: 0.43, 0.32, 0.14

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDvHD63jcQ2mg3Pc8RAtDlAJsH3Lqab9NYhQC3Dift98 up+Fv9UQCfalu1
PUVFbiUKEaDQYATcGPpmM7M=
=vvGt
-----END PGP SIGNATURE-----
Jan 5 '06 #5

"Iván Sánchez Ortega" <i.***************@rroba--mirame.punto.net> schreef in
bericht news:m1************@blackspark.escomposlinux.org.. .
tomb wrote:
But the only reason to generate neat html
is so the users can look at the page source and make sense of it more.
Besides, a developer should not read raw HTML, but should have a look at
the
DOM tree - there are wonderful DOM tree inspectors for Konqueror and
Firefox (built-in) and for IE (via third-party toolbars).

Analyzing the DOM tree generated by the PHP scripts, and validating the
generated HTML against W3C's validators would prove more useful than
writing scripts that generate indented HTML.


I'm just working on some inherited code, and I don't want to rewrite it
completely.
What I do now is load source of the resulting page into CSE Html Validator.
If would help me a bit to make it more readable;
but you are right: a comment blocks will do fine.

Thanks for your input,
Jean.

(In fact, my programs generate a gibberish of (X)HTML that validates quite
nicely, but is a mess to read).

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

Jan 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Ehmer | last post by:
Appreciate any ideas about what might be happening with these pages in IE5.2 Mac. In summary the 2nd paragraph or list item is indenting to the right. paragraphs of list items after the 2nd...
2
by: RobG | last post by:
Some posters have been critical of the lack of formatting in some posts. Pleae be aware that posting through the Google group's web interface removes *all* leading white space - tabs, spaces, the...
9
by: bob | last post by:
What tool do most of you people use to indent your code? Doing so by hand is a bit tedious, I think.
1
by: sh4r4d | last post by:
Can any tell how this automatic C indenting done in some editors like Vim, Emacs (in C-mode), because I want to change my program which now give result after seeing full grammer, while these...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
2
by: Leon Friesema | last post by:
Hiyall! I have a RichTextBox inside a UserControl which should be able to indent a block off text (or UnIndent for that matter) like the SourceEditor of VS2003 or WinWord does. All controls on...
7
by: Harrie | last post by:
Hi group, I want to indent existing XML files so they are more readable (at least to me). At this moment I'm looking at the XML files OpenOffice.org's Writer application produces in it's zipped...
0
by: D. Shane Fowlkes | last post by:
The Smart Indenting "feature" is driving me absolutlely crazy in VWD. Problem: VWD in Code View insists on tabbing a lot of my code over to it's own liking and effects mainly my comments in the...
6
by: eugene.morozov | last post by:
Hello, Does anyone know how to make python-mode correctly indent nested lists and dictionaries. I hate indenting Django url patterns and Zope Archetypes schemas by hand, because python-mode...
4
by: Christopher | last post by:
How would I go about indenenting for each level of recursion, if I am trying to output the contents of a class which contains its own type? where AttributeGroupMap is typdef...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.