Find out how many lines will a text expand?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheProgrammer
Forum Newbie
Posts: 22
Joined: Mon Nov 27, 2006 12:25 am

Find out how many lines will a text expand?

Post by TheProgrammer »

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 :roll: ). 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 :D 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. :D

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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

This is a design error and should not be handled with PHP. Even if you do cut the string to a fixed length what going to happen if the client doesn't have the right font installed or changes the font size with the browser?
_ca_
Forum Newbie
Posts: 12
Joined: Wed Oct 25, 2006 4:38 pm

Post by _ca_ »

I agree, this is hard to fix in PHP.

You could use a simple css (<p style="height: 200px;overflow: auto">), or a different designer ;)
Post Reply