lIP TT lIP TT - 3 months ago 12
PHP Question

PHP finish text with ... if it is too long

I have got div with width of 300 and i have also got children span in it text of which doesn't depend on me.If span's text is

'WWWWWWWWWW'

It should stop after five

W
,but if text is

'llllllllll'
It should stop after 10
l
's

Answer

There's no need to apply any PHP programming logic here.

This thing can be achieved in CSS easily.

.text-ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

And add this class to your span:

<span class="text-ellipsis">WWWWWWWWWWWWW</span>