summaryrefslogtreecommitdiff
path: root/inc/functions.php
diff options
context:
space:
mode:
authorMichael Foster <savetheinternet@tinyboard.org>2013-07-28 20:33:26 -0400
committerMichael Foster <savetheinternet@tinyboard.org>2013-07-28 20:33:26 -0400
commit57c8e4ee7cea126e68ade4913c57a46f06d1a2b0 (patch)
tree6328d36c6e345878a320c5cfcf2b2b1f69c89fdf /inc/functions.php
parentcea7881749e85b4ba5c8444e738d42a27d91244f (diff)
Strip combining characters from Unicode strings (eg. Zalgo)
Diffstat (limited to 'inc/functions.php')
-rw-r--r--inc/functions.php48
1 files changed, 47 insertions, 1 deletions
diff --git a/inc/functions.php b/inc/functions.php
index b5660664..9d398002 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -1526,7 +1526,53 @@ function utf8tohtml($utf8) {
return htmlspecialchars($utf8, ENT_NOQUOTES, 'UTF-8');
}
-function buildThread($id, $return=false, $mod=false) {
+function ordutf8($string, &$offset) {
+ $code = ord(substr($string, $offset,1));
+ if ($code >= 128) { // otherwise 0xxxxxxx
+ if ($code < 224)
+ $bytesnumber = 2; // 110xxxxx
+ else if ($code < 240)
+ $bytesnumber = 3; // 1110xxxx
+ else if ($code < 248)
+ $bytesnumber = 4; // 11110xxx
+ $codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
+ for ($i = 2; $i <= $bytesnumber; $i++) {
+ $offset ++;
+ $code2 = ord(substr($string, $offset, 1)) - 128; //10xxxxxx
+ $codetemp = $codetemp*64 + $code2;
+ }
+ $code = $codetemp;
+ }
+ $offset += 1;
+ if ($offset >= strlen($string))
+ $offset = -1;
+ return $code;
+}
+
+function strip_combining_chars($str) {
+ $chars = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
+ $str = '';
+ foreach ($chars as $char) {
+ $ord = ordutf8($char, $o = 0);
+
+ if ($ord >= 768 && $ord <= 879)
+ continue;
+
+ if ($ord >= 7616 && $ord <= 7679)
+ continue;
+
+ if ($ord >= 8400 && $ord <= 8447)
+ continue;
+
+ if ($ord >= 65056 && $ord <= 65071)
+ continue;
+
+ $str .= $char;
+ }
+ return $str;
+}
+
+function buildThread($id, $return = false, $mod = false) {
global $board, $config;
$id = round($id);