Archive for April 5th, 2009
How do I truncate an HTML string without breaking the HTML code?
Sometimes on a website, you just want to show the first few hundred characters of a text as an introduction, and link to the full text. But by simply using the PHP substr() function, you’re likely to break the HTML code or cut words in half. The PHP function below allows you to maintain your HTML and complete words while trimming your HTML string. The code is from the cakephp framework.
Links:
www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags
www.cakephp.org