NEONecd999 Posted August 8, 2007 Share Posted August 8, 2007 I have a box of a fixed size in my site layout where a field from a MySQL table is outputted. However, this field's length can change, sometimes longer than the size of the box in the design. In CSS, i set the div to overflow:hidden, but I would like the php to actually shorten the text being outputted with a "..." at the end of the text. This cannot be done by limiting the number of characters as different characters are different widths, especially line breaks (which can be a whole line long). Is there any way of limiting text output by the size of the area it takes up? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/63893-shorten-text-output/ Share on other sites More sharing options...
trq Posted August 8, 2007 Share Posted August 8, 2007 Is there any way of limiting text output by the size of the area it takes up? Nope. PHP has no concept of text size. Quote Link to comment https://forums.phpfreaks.com/topic/63893-shorten-text-output/#findComment-318462 Share on other sites More sharing options...
gerkintrigg Posted August 8, 2007 Share Posted August 8, 2007 you can use explode to limit the size (didn't I just mention this in another post?)... $var_string='hello how are you?'; $var=explode(' ',$var_string); echo $var[0]; that then echoes the first word of the string (in this case "hello") perhaps that could be something worth doing...? Quote Link to comment https://forums.phpfreaks.com/topic/63893-shorten-text-output/#findComment-318474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.