Diferior CMS on steroids
+1427 / 2338640 ( online 9 )

Non-english names and usernames


Avatar
Forum posts: 9
ZigmunD (Junior member) @ 09 03 11 - 05:19:11
1. We need replace for function strlen because strlen unable to count non-english characters correctly in multi-byte strings (for example, utf8).

Open functions/text.php and add following lines to „text“ class. For example, on line #822, after get_smilies function:
public function utf8_strlen($s) { $c = strlen($s); $l = ; for ($i = ; $i < $c; ++$i) if ((ord($s[$i]) & 0xC0) != 0x80) ++$l; return $l; }

2. Make Diferior use utf8_strlen instead of strlen.
Open functions/user.php and change
line #218 to
$strl_user = $text -> utf8_strlen ( $user );

line #625 to
$strl_name = $text -> utf8_strlen ( $name );

3. Make Diferior allow non-english characters in names and usernames.
Open functions/text.php and change
line #527 to
return (bool)preg_match ( "#^[\pL0-9_\-\+\.,:@%\^\*=\[\]{}]+\$#", $str );

line #535 to
return (bool)preg_match ( "#^[\pL0-9, ]+\$#i", $str );

I don't know if code clean or dirty but that solves my problem with russian names. :)
Avatar
Blog posts: 11
Added downloads: 2
Comments: 18
Forum posts: 573
UnrealX (Lead code monkey) @ 09 03 11 - 10:52:52
Thanks for contributing, appreciate it! ;)