I have a string which contains HTML tags. I’m looking for a piece of code that would let me truncate this string to:
- have 100 characters length,
- contain no image tags (
<img />). - include other HTML tags (except image tag),
- that 100 characters lenght should not include white spaces and HTML tags characters.
For example, the string is:
<img>Something</img><b>Just an Example</b> Plain Text <br><a href="#">stackoverflow</a>
So the result should be:
Just an Example Plain Text stackoverflow (its a link).
As a result we have around 35 words (except white-space).
I tried solution from this question, but didn’t get required result. Any help would be appreciated.
How about a function. Here’s mine —
AbstractHTMLContents. It has two parameters:Here’s the code:
It seems, it gives result expected by you.