what is the best method to count a *real & full* text height in block of html code?
I need to count text height in html block. S开发者_如何学编程o i will know is this block overflows screen or not (for example). All i have is just html code taken from database. Of course it can or can't have br's, p's or div's, so counting it is not a good idea. Also the styles can change their attributes. I need to do this on server side on PHP. Anyone has do this already?
The solution can be in 10% not accurate - its OK.
Thank you, Sergey
You can't answer that in abstract: web sites are not still pictures, they are complex documents designed to be displayed inside very different kind of devices.
You might be able to find an answer if you pick a concrete scenario: a given HTML+CSS rendering engine plus a certain set of configuration options (available fonts, font renderer settings, viewport size and resolution...). That is to say, you basically have to send the document to an browser and either grab a screenshot and analyse it yourself or make the browser send you back the information.
There are HTML engines designed for off-screen rendering: I can think of wkhtmltopdf, which is a tool to convert HTML to PDF using webkit. The question is whether you actually need one.
IMHO, your best chance is to send your document to a real desktop browser and write some JavaScript code to gather and send back the information.
精彩评论