Limit text inside div, using Div height

2019-05-29 07:50发布

问题:

I'm currently working on a website. One of the things it will do is allow the admin to post news. all my news divs are fixed in height and width.
PHP queries the database for the text and cuts it at 500 characters lenght, so the text doesn´t exit my div.
Of course this is not the best approach since if I use all caps, 500 caps characters take more space than 500 normal ones....
If I also use the /br/ tag to change lines, that is also a problem, since php ->(i think) won't count that as empty spaces...

As the title suggests... I would like to know if there is any way of limiting the ammount of text in my div by using it's height....

Thanks in advance!

回答1:

Have a look at http://www.w3schools.com/css/pr_pos_overflow.asp.



回答2:

I thinks the best way is to use css in combination with a php function that limits/cuts the string and removes any html tags and tabs.

The css: min-height: 100px;

And a php function you could use is: http://php.net/manual/en/function.strip-tags.php and http://php.net/manual/en/function.substr.php