Page 1 of 1

Is there a PHP script that can spot long individual words?

Posted: Wed Nov 18, 2015 10:09 am
by simonmlewis
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....??

Re: Is there a PHP script that can spot long individual word

Posted: Wed Nov 18, 2015 10:18 am
by Celauran
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.

Re: Is there a PHP script that can spot long individual word

Posted: Wed Nov 18, 2015 5:07 pm
by Christopher
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....??
Is is just exclamation points? If it's sentence end punctuation, you could this do before saving:

Code: Select all

$comment = str_replace(array('!!!!', '????', '....'), '', $comment);