Jump to content

Shorten TEXT output


NEONecd999

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/63893-shorten-text-output/
Share on other sites

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...?

Link to comment
https://forums.phpfreaks.com/topic/63893-shorten-text-output/#findComment-318474
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.