codrgii Posted June 17, 2011 Share Posted June 17, 2011 how can i check to see if a poster has posted similar words when posting something? i want to stop them posting something like "hhhhh" or "aaaaa" and so on, how in php can that be done? Quote Link to comment https://forums.phpfreaks.com/topic/239688-filter-similar-letters/ Share on other sites More sharing options...
Fadion Posted June 18, 2011 Share Posted June 18, 2011 You can do a simple search: <?php $banned_words = array('hhhhh', 'aaaaa'); foreach ($banned_words as $word) { if (strpos($word, $text)) { echo "$word is not allowed! Don't asked me why!"; } } ?> or replace those words directly: <?php $search = array('hhhhh', 'aaaaa'); $replace = ''; $text = str_replace($search, $replace, $text); ?> EDIT: Now I'm seeing I totally misunderstood your question. Sorry. Quote Link to comment https://forums.phpfreaks.com/topic/239688-filter-similar-letters/#findComment-1231291 Share on other sites More sharing options...
Psycho Posted June 18, 2011 Share Posted June 18, 2011 Are you looking for similar words OR words with repeated letters? When trying to filter user input you must be VERY specific as to your requirements. Quote Link to comment https://forums.phpfreaks.com/topic/239688-filter-similar-letters/#findComment-1231293 Share on other sites More sharing options...
codrgii Posted June 18, 2011 Author Share Posted June 18, 2011 Are you looking for similar words OR words with repeated letters? Basically i would like to filter out any junk posts with the same words in sequence more than 4 times, and if found then cancel/end the script. Quote Link to comment https://forums.phpfreaks.com/topic/239688-filter-similar-letters/#findComment-1231294 Share on other sites More sharing options...
xyph Posted June 18, 2011 Share Posted June 18, 2011 Use regex, I suppose This will match when someone repeats a single character 4 or more times in a row. Unicode-safe $expr = '/(\X)\1{3,}+/u'; The same word/character etc is below $expr = '/(\X+?)\1{3,}+/u'; These expressions are extremely slow, especially the second one. Tons of backtracking. Quote Link to comment https://forums.phpfreaks.com/topic/239688-filter-similar-letters/#findComment-1231345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.