(Following this question: html columns whose width automatically changes according to their content )
From a PHP script, I print some HTML code, and I would like to know what will be the height of the result (for paging calculation). Suppose I have the following input:
- $html code I want to print (string);
- $css code, with full details of the font and size of all items that appear in the HTML (string);
- all relevant browser settings (fonts, sizes, etc.);
- page $width, in pixels (int).
I create a page that looks like this:
<html>
<head>
<style>$css</style>
</head>
<body style='width:$width'>
$html
</body>
</html>
I want to know, from within the PHP script, the number of pixels from the top of the page to the bottom of the text.
EDIT: I need to do this on the server side, before the content is displayed, because I use this to calculate what content to put. For example, if the content is too high, I might decide to put only the first half, etc.
Another possible use is to calculate what width is needed to achieve a particular height. For example, I might try to put it in a div with width 200px, but then the result may be too high; then I try width 400px, etc., until I find the width the gives the height that I want.