473,850 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1828
-----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*********@kde talk.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFDu/bY3jcQ2mg3Pc8RA n+dAJ9nKfBduWiH ByebT4SBBh+o6vQ gBQCfc5cD
8j+DvfHPubYwhvU bgJAdjJc=
=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("Hell o world");
$divMiddle = createDiv($divI nner);
$divOuter = createDiv($divM iddle, ' ');

?>
<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)

iD8DBQFDvHD63jc Q2mg3Pc8RAtDlAJ sH3Lqab9NYhQC3D ift98up+Fv9UQCf alu1
PUVFbiUKEaDQYAT cGPpmM7M=
=vvGt
-----END PGP SIGNATURE-----
Jan 5 '06 #5

"Iván Sánchez Ortega" <i.************ ***@rroba--mirame.punto.ne t> 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
1693
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 don't indent further, they just stay in line with the 2nd. Also seems to be affecting headings (h2 etc) and images. Seems to be a problem specific to this browser.
2
1314
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 lot. It also wraps at very short line lengths, making it something of a chore to use. Please allow some leeway for those posting via the web interface, for some there is no option. I've been forced to ditch my normal
9
1831
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
1513
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 editor predict only seeing partial grammer.
102
5774
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 can't tell where a bracket is missing.... a few weeks have past, I requested a feature for the delphi ide/editor "automatic identation of code in begin/end statements etc" and today when I woke up I suddenly released a very simple solution for this...
2
4981
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 the form (except for the RichTextBox) have TabStop=False and I have a KeyDown event handler which calls the IndentSelection function. No problem with the indenting (I've watched when stepping through the code) except.. The e.Handled does not seem...
7
2264
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 "SXW" format (and they're one line, probably to save space, which I find hard to read). At first I thought I was going to do it with sed/awk or something like that, but then I remembered the xsl:output element with the indent attribute of XSL and...
0
1008
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 code. First of all, I've searched the help files and searched forums.asp.net. I can't seem to find a solution so I thought I'd try here. When I look at Tools >> Options and look under Text Editor >> All Languages >> Tabs, it has a subtle...
6
1650
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 indents them in incorrect and ugly way. Here's how it should be: StringField('reference', widget=StringWidget( description='Position reference'
4
3840
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 std::map<std::string, AttributeGroup *AttributeGroupMap; const std::string AttributeGroup::ToString() const { std::stringstream ss;
0
9741
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11011
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10666
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10724
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5929
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4140
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.