Forum Moderators: open

Message Too Old, No Replies

Word or character count, excluding html tags

What's the best way?

         

codebreaker

6:14 pm on Aug 6, 2004 (gmt 0)

10+ Year Member



I am doing a news headlines section, where I would like to display, say, the first 50 characters or maybe the first 15 words of a string. But the string may have unescaped tags (eg., <BR>) that shouldn't count in the total. What's the most efficient way to do this?Also a concern is that the headline not end with an open tag (like a link). By this I mean two things:

<a href="http://ww

...and...

<a href="http://www.webmasterworld.com">WebMast

This is an interesting problem. I can think of a few ways to go at it, but what is the best way? Let's assume that a less-than character denotes a tag, and that there will be a greater-than character up stream.

BlobFisk

6:39 pm on Aug 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like a mixture of regular expressions and substring should do the job for you...