I have a form that allow user input product description, and in the list page I want to print out product description in brief (just few lines).
But the description contains html tags, I’ve tried some solutions, but they can’t solve my problem.
(e.g:If I shorten the text by using sub string function, but it will have problem with unclosed tag)
You could do a quick tag stripping, and add an ellipsis at the end for added decoration:
Beware that strip_tags() is not foolproof and can mess up the text if you have malformed html tags, but it’s a “quick&dirty” solution; otherwise you’ll need to parse the html with a proper tool (DOMDocument for example, or better parsers) and then do your
substr()