I'd like to use preg_replace to remove excessive characters.

IE: User enters ARGHHHHHHHHHHHH. When I would like preg_replace to notice that there are more than 5 H's in there, so it shortens it down to ARGHHHHH. I would like this to work with any character, IE: !!!!!!!!!!!!!!!!!!!! or any other little annoying thing a user can put in. Thanks.

    There's probably a more efficient way, but something like this might work:

    preg_replace('/(.)\1{4,}/', substr('\\1', 0, 5), $string);

      that would work, only it produced no matches. it would probably be more efficient just to break up the string into sections no matter what it looked like since the real problem is how big a word is, but now that the question has come up, hopefully someone will ease my curiosity and have the answer. :bemused:

        The board apparently dropped some slashes. Let's see if I can have it show correctly

        preg_replace('/(.)\\1{4,}/', substr('\\\\1', 0, 5), $string);

        *edit: Ok, I think that looks right now.

          Write a Reply...