Find out how many lines will a text expand?
Posted: Mon Nov 27, 2006 12:40 am
Hello people!
Here's what I'm trying to do. I must extract some text out from a Mysql database and write it down in a page that must have rigid (unalterable) width/height (it uses a lot of images and will screw up if more text lines are inserted - god, these designers
). Anyway, the width is no problem as I can set it with css from the begining but in case the text extracted from the database will take too much space (height), it's quite stupid.
The obvious solution is to trim it at the end, eventually add three dots so people will know that it's more text there. But how do I know how many lines the text will take? I have a fix font (Verdana, bold) and a fix font size (10px), but this is not much help.
The stupid solution
would require me to write a text down in Photoshop for example with every letter, measure the widths of wach letter and symbol than make an array of these widths, and by doing this i will be able to calculate the entire with of the text, and so, how many lines will take. You imagine, i find it quite unefficient, so I thought you guys might know some tricks. An estimation for the number of lines would do, it doesn't have to be exact. If you can give me a hand I would really appreciate it.
PS: ohh, i thought also at imagettfbox function but from what I can tell this only gives you the size of the text if you write the text on one line. It's not the case.
Thank you very much,
Cristian
Here's what I'm trying to do. I must extract some text out from a Mysql database and write it down in a page that must have rigid (unalterable) width/height (it uses a lot of images and will screw up if more text lines are inserted - god, these designers
The obvious solution is to trim it at the end, eventually add three dots so people will know that it's more text there. But how do I know how many lines the text will take? I have a fix font (Verdana, bold) and a fix font size (10px), but this is not much help.
The stupid solution
PS: ohh, i thought also at imagettfbox function but from what I can tell this only gives you the size of the text if you write the text on one line. It's not the case.
Thank you very much,
Cristian