View Single Post
  #1 (permalink)  
Old July 3rd, 2009, 03:48 AM
rjonk rjonk is offline
Authorized User
Points: 204, Level: 4
Points: 204, Level: 4 Points: 204, Level: 4 Points: 204, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2006
Location: Haarlem, , Netherlands.
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default truncate text including tags

My mission is to output a text block in html and truncate the text at around a specific amount of characters. But the text can hold some extra inline tags like anchor tags. Not tables. I only want to count the rendered text not the markup. When I want to truncate the text and put an ellipsis after the text I don't want the tag to be truncated so that I end up with invalid html. Has anybody had this mission before and can help me solving this problem.
For example truncate a text at say around 20 characters. And the xml is "I want to be <a href='#'>truncated</a> here.
The output must be "I want to be <a href='#'>truncat</a>..." in the browser you see : I want to be truncat... . I don't ask for a total code but just a hint how my strategy should look like ( total code is always appreciated :-)

Last edited by rjonk : July 3rd, 2009 at 03:50 AM.
Reply With Quote