|
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]
|