chucky91
Advanced OT User
- Joined
- Apr 8, 2010
- Messages
- 299
- Solutions
- 10
- Reaction score
- 157
Meaningless names when creating characters!
Im using this script that prevents me from creating a character with repeated and equal syllables,
and triple characters, but it still needs improvements.
If anyone is willing to improve!
Im using this script that prevents me from creating a character with repeated and equal syllables,
and triple characters, but it still needs improvements.
If anyone is willing to improve!
PHP:
if(!blockString($name) || !blockNames($name)){
error_("Your name contains blocked words.");
error_(Validator::getLastError());
}
function blockString($texto) {
$vog = array('a', 'e', 'i', 'o', 'u');
$t = strlen($texto);
$count_char = 0;
$count_vog = 0;
$t_vog = false;
for ($i = 0; $i < $t; $i++) {
$letraAtual = strtolower($texto[$i]);
if (in_array($letraAtual, $vog)) {
$t_vog = true;
$count_vog++;
$count_char = 0;
if ($count_vog >= 3) {
return false;
}
} else {
$count_char++;
$count_vog = 0;
if ($count_char >= 3) {
return false;
}
}
}
if (!$t_vog) {
return false;
}
return true;
}
function blockNames($name) {
$w1 = str_split($name, 2);
$wordCount = array_count_values($w1);
foreach ($wordCount as $word => $count) {
if (strlen($word) === 2 && $count > 3) {
return false;
}
}
$w2 = explode(' ', $name);
$wordCount2 = array_count_values($w2);
foreach ($wordCount2 as $w2 => $count2) { // if one word more 4 char for repeat more 1, blocked.
if (strlen($word) >= 2 && $count2 > 1) {
return false;
}
}
return true;
}