We are getting a lot of user comments where users are enter thousands of !!!!!!!!!!!!!!!! in their comments.
While we are not making them live, it is causing havoc with the screen to check for the comments.
So is there a simple way to find the "longest word" in a string, and count how many characters it is. Thus stopping it from being posted if it is over say, 20 characters....??
Is there a PHP script that can spot long individual words?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Is there a PHP script that can spot long individual words?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Is there a PHP script that can spot long individual word
You could explode the string on space to break it into individual words, strlen each words, and go from there. Might be a more elegant solution, but that's certainly dead simple.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Is there a PHP script that can spot long individual word
Is is just exclamation points? If it's sentence end punctuation, you could this do before saving:simonmlewis wrote:We are getting a lot of user comments where users are enter thousands of !!!!!!!!!!!!!!!! in their comments.
While we are not making them live, it is causing havoc with the screen to check for the comments.
So is there a simple way to find the "longest word" in a string, and count how many characters it is. Thus stopping it from being posted if it is over say, 20 characters....??
Code: Select all
$comment = str_replace(array('!!!!', '????', '....'), '', $comment);(#10850)