Truncate a HTML formatted text.

Posted by marharépa on Stack Overflow See other posts from Stack Overflow or by marharépa
Published on 2010-04-19T21:29:26Z Indexed on 2010/04/19 21:33 UTC
Read the original article Hit count: 293

Filed under:
|
|
|
|

Hi there!

I've got a variable which is formatted with random HTML code. I call it to {$text} and i truncate it.

The value is for example:

<div>Lorem <i>ipsum <b>dolor <span>sit </span>amet</b>, con</i> elit.</div>

If i truncate the text's first ~30 letters, I'll get this:

<div>Lorem <i>ipsum <b>dolor <span>sit 

The problem is, I can't close the elements. So, I need a script, which check the <*> elements in the code (where * could be anything), and if it dont have a close tag, close 'em.

Please help me in this. Thanks.

© Stack Overflow or respective owner

Related posts about html

Related posts about truncate