Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.