Dodona gives you answers

Archive for April 2009

How do I truncate an HTML string without breaking the HTML code?

with 18 comments

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

Read the rest of this entry »

Written by lutsen

April 5, 2009 at 1:55 pm

Posted in PHP