The problem is simple:
Using tinyMCE, I am storing html data into the database. Then at the home page, I am showing 5 latest posts I've inserted into the database. I want to crop each of these posts to the specified length if they exceed it and put a continue reading
link (can be a soft crop here, doesn't have to be rigid).
It would be easy to crop the string with php's wordwrap
function but since the string is composed of html I don't wanna ruin the html code by cropping it from a wrong place.
So the question is: Is there an easy way to crop this, (can be a css, javascript solution as well) or do I have a write a long function with lots of checks to implement such a basic feature? I was thinking to use the DOM
class but before creating function I just wanted to ask you guys.
EDIT
Styling is essential to me. So there is no possibility to strip the tags.
Thanks in advance.
One possible solution could be to strip tags, if the styling of this HTML is not vital, so you can cut wherever you want: http://php.net/manual/es/function.strip-tags.php
Another solution for CSS3 browsers, would be to use text-overflow, read more about this: http://davidwalsh.name/css-ellipsis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With