Page 1 of 1

Removing long words from a string

Posted: Mon Aug 09, 2004 5:50 am
by Toneboy
Come across a problem on one of my sites with a feed. One of my users has put in a post where for the purposes of underlining she has put in umpteen "-" characters (where one <hr> would have sufficed, alas). As a result of this the format on the front page is temporarily knocked out of alignment.

This data is held within a MySql database, and a number of conditions are put on the parsed text already, e.g. strip_tags.

What would be the best answer to this problem?

So far I've considered:

1) Cheating by using the wordwrap command.
2) Cheating by using ereg_replace or preg_replace to take the "-" character out of the feed.

But I figure there must be a better way to do this, just haven't been able to find it. Can anyone suggest one?

P.S. I would probably make a limit of twenty characters to a word, that seems a reasonable amount.

html Area

Posted: Mon Aug 09, 2004 5:56 am
by anjanesh
If you are considering style textarea you might also want to try out this html Area :
http://www.interactivetools.com/products/htmlarea/
Its amazing with lots of functionality including <HR>.

Posted: Tue Aug 10, 2004 8:11 am
by Toneboy
Got this tip from a friend of mine:

Code: Select all

// In this example words 25 characters or longer are not shown.
$newstext = preg_replace("/[a-zA-Z0-9]{25,}/s", "", $newstext);