Reply to Re: indenting

Your name:

Reply:


Posted by Toby Inkster on 10/11/74 11:36

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация