I've been looking around the web and thinking about it, but I can't find the solution, though I know it's there somewhere.
Here's the problem. I've got a string, and let's say it contains the contents of an article on the site. I want to generate a preview of the article by getting the first 400 characters and displaying them followed by a "Read More" link.
That's easy enough. But the problem is, the article contains HTML. I need to know how to:
- Avoid splitting tags in half at the end of the preview, eg "Blah blah blah <a hre". That's bad.
- Close up any tags that remain open, eg "Blah blah <em>bla"...Notice that <em> is never closed.
I know there's a way to do this, because I've seen sites that do it. Anyone have any ideas?
Here's the problem. I've got a string, and let's say it contains the contents of an article on the site. I want to generate a preview of the article by getting the first 400 characters and displaying them followed by a "Read More" link.
That's easy enough. But the problem is, the article contains HTML. I need to know how to:
- Avoid splitting tags in half at the end of the preview, eg "Blah blah blah <a hre". That's bad.
- Close up any tags that remain open, eg "Blah blah <em>bla"...Notice that <em> is never closed.
I know there's a way to do this, because I've seen sites that do it. Anyone have any ideas?