Jump to content

filter similar letters


codrgii

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.