I have some content (some from an external source, some specially written) that is displayed in a kind of blog format. I want to cut off the text after a certain number of characters, so currently I'm doing this:
<?=substr( strip_tags($a['content']), 0, 400 )?>
The problem is, this loses all the formatting and I just get one massive blob of text. But if I don't strip the tags, obviously some tags will go unclosed and mess up the layout.
What would be a good way to truncate after X number of characters, but also keep some basic formatting?