Calculate the log odd probability that inserted string from keyboard
is in Arabic language

@param string $str Inserted string from the keyboard

@return float Calculated score for input string as Arabic language
@author Khaled Al-Sham'aa
979581
protected function checkAr($str) 
    {
        $lines  = $this->_arLogodd;
        $logodd = array();
        
        $line   = array_shift($lines);
        $line   = rtrim($line);
        $second = preg_split("/\t/", $line);
        $temp   = array_shift($second);
        
        foreach ($lines as $line) {
            $line   = rtrim($line);
            $values = preg_split("/\t/", $line);
            $first  = array_shift($values);
            
            for ($i=0; $i<37; $i++) {
                $logodd["$first"]["{$second[$i]}"] = $values[$i];
            }
        }
        
        $max  = mb_strlen($str, 'UTF-8');
        $rank = 0;
        
        for ($i=1; $i<$max; $i++) {
            $first  = mb_substr($str, $i-1, 1, 'UTF-8');
            $second = mb_substr($str, $i, 1, 'UTF-8');
     
            if (isset($logodd["$first"]["$second"])) {
                $rank += $logodd["$first"]["$second"]; 
            } else {
                $rank -= 10;
            }
        }

        return $rank;
    }
404933
public static function str_utf8_mix_word_count($str = "")
    {
        $str = preg_replace(self::UTF8_SYMBOL_PATTERN, "", $str);
        return self::str_utf8_chinese_word_count($str) + str_word_count(preg_replace(self::UTF8_CHINESE_PATTERN, "", $str));
    }
802330
public static function bytes2int($str, $l = false)
    {
        if ($l) {
            $str = strrev($str);
        }
        $dec = 0;
        $len = mb_orig_strlen($str);
        for ($i = 0; $i < $len; ++$i) {
            $dec += ord(mb_orig_substr($str, $i, 1)) * pow(0x100, $len - $i - 1);
        }
        return $dec;
    }
680854
public static function strlen($str) {
    if (is_array($str))
      return false;

    if (function_exists('mb_strlen'))
      return mb_strlen($str, 'UTF-8');

    return strlen($str);
  }
1069458
static private function PositionEndingBraceSQL( 
        string & $str
	) : int {
	
        $ret = -1;
        $search1 = false;
        $search2 = false;
        $level = 0;
        
        // echo "\n PositionEndingBraceSQL( \"{$str}\" ) ";
        
        // skip spaces
        
        for ( $i = 0; $i < strlen( $str ); $i++ ) {
            if ( ! ctype_space( substr( $str, $i, 1 ) ) ) {
                break;
            }
        }
        
        if ( substr( $str, $i, 1 ) == '(' ) {     
        
            // echo "\n '(' detected";
        
            for ( $i = $i + 1 ; $i < strlen( $str ); $i++ ) {     // start with1 in order to skip first brace
            
                // echo "\n $i ->" . substr( $str, $i );
                
                if ( $search1 ) {
                    if ( substr( $str, $i, 1 ) != '"' ) {
                        continue;
                    }
                    $search1 = false;
                    continue;
                }
                
                if ( $search2 ) {
                    if ( substr( $str, $i, 1 ) != "'" ) {
                        continue;
                    }
                    $search2 = false;
                    continue;
                }
                
            
                if ( substr( $str, $i, 1 ) == '"' ) {
                    $search1 = true;                
                    continue;
                }
                
                if ( substr( $str, $i, 1 ) == "'" ) {
                    $search2 = true;                
                    continue;
                }       
                
                if ( substr( $str, $i, 1 ) == "(" ) {
                    // a new brace level was opened
                    $level++;    
                }             
            
                if ( substr( $str, $i, 1 ) == ')' ) {
                    if ( ! $level ) {
                        $ret = $i;
                        break;
                    } 
                    
                    $level --;
                    
                }
                
            }        
        
        }
        
        // echo "\n PositionEndingBraceSQL( ) returns $ret";
        
        return $ret;
	
	}
1062683
private function charPad($str)
    {
        $l = strlen($str)*8;     // # of bits from input string
        $str .= "\x80";          // append the "1" bit followed by 7 0's
        $k = (512 - (($l + 8 + 64) % 512)) / 8;   // # of 0 bytes to append
        $k += 4;    // PHP String's will never exceed (2^31)-1, so 1st 32bits of
                    // the 64-bit value representing $l can be all 0's
        for ($x = 0; $x < $k; $x++) {
            $str .= "\0";
        }
        // append the last 32-bits representing the # of bits from input string ($l)
        $str .= chr((($l >> 24) & 0xFF));
        $str .= chr((($l >> 16) & 0xFF));
        $str .= chr((($l >> 8) & 0xFF));
        $str .= chr(($l & 0xFF));
        return $str;
    }
1205765
public static function absLength($str) {
		if (empty($str)) {
			return 0;
		}
		if (function_exists('mb_strlen')) {
			return mb_strlen($str,'utf-8');
		}
        preg_match_all("/./u", $str, $ar);
        return count($ar[0]);
	}
29094
private static function utf8ToUnicode($str) {
    $new = array();
    $len = iconv_strlen($str);
    for ($n = 0; $n < $len; $n++) {
      $char = iconv_substr($str, $n, 1);
      $new[] = self::uniord($char);
    }
    return $new;
  }
915957
private function _do($str)
    {
        $str = (string) $str;
        $strInt = (int) $str;
        $strFloat = (float) $str;
        if (
            !$str
            ||
            (string) $strInt === $str
            ||
            (string) $strFloat === $str
        ) {

            // no xss found
            if ($this->_xss_found !== true) {
                $this->_xss_found = false;
            }

            return $str;
        }

        // remove the BOM from UTF-8 / UTF-16 / UTF-32 strings
        $str = UTF8::remove_bom($str);

        // replace the diamond question mark (�) and invalid-UTF8 chars
        $str = UTF8::replace_diamond_question_mark($str, '');

        // replace invisible characters with one single space
        $str = UTF8::remove_invisible_characters($str, true, ' ');

        // normalize the whitespace
        $str = UTF8::normalize_whitespace($str);

        // decode UTF-7 characters
        $str = $this->_repack_utf7($str);

        // decode the string
        $str = $this->_decode_string($str);

        // remove all >= 4-Byte chars if needed
        if ($this->_stripe_4byte_chars) {
            $str = (string) \preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
        }

        // backup the string (for later comparision)
        $str_backup = $str;

        // remove strings that are never allowed
        $str = $this->_do_never_allowed($str);

        // corrects words before the browser will do it
        $str = $this->_compact_exploded_javascript($str);

        // remove disallowed javascript calls in links, images etc.
        $str = $this->_remove_disallowed_javascript($str);

        // remove evil attributes such as style, onclick and xmlns
        $str = $this->_remove_evil_attributes($str);

        // sanitize naughty JavaScript elements
        $str = $this->_sanitize_naughty_javascript($str);

        // sanitize naughty HTML elements
        $str = $this->_sanitize_naughty_html($str);

        // final clean up
        //
        // -> This adds a bit of extra precaution in case something got through the above filters.
        $str = $this->_do_never_allowed_afterwards($str);

        // check for xss
        if ($this->_xss_found !== true) {
            $this->_xss_found = !($str_backup === $str);
        }

        return $str;
    }
1165255
public static function toNumber($str)
    {
        if (is_string($str)) {
            $str = preg_replace("~[^0-9-.]~", "", $str);
        }
        return (strpos($str, ".") === false)
            ? intval($str)
            : floatval($str);
    }
273290
public function convertToUtf8($str) {
        if (mb_detect_encoding($str, "UTF-8, ISO-8859-1, GBK")!="UTF-8") {
            $str = utf8_encode($str);
        }
        $str = iconv('UTF-8', 'UTF-8//IGNORE', $str);
        return $str;
    }
562273
static function is_utf8($str)
    {
        $c=0; $b=0;
        $bits=0;
        $len=strlen($str);
        for($i=0; $i<$len; $i++)
        {
            $c=ord($str[$i]);
            if($c > 128)
            {
                if(($c >= 254)) return false;
                elseif($c >= 252) $bits=6;
                elseif($c >= 248) $bits=5;
                elseif($c >= 240) $bits=4;
                elseif($c >= 224) $bits=3;
                elseif($c >= 192) $bits=2;
                else return false;
                if(($i+$bits) > $len) return false;
                while($bits > 1)
                {
                    $i++;
                    $b=ord($str[$i]);
                    if($b < 128 || $b > 191) return false;
                    $bits--;
                }
            }
        }
        return true;
    }
1293836
public static function unicode_to_utf8($str)
    {
        if (extension_loaded('mbstring')) {
            return preg_replace_callback(
                '/\\\\u([0-9a-fA-F]{4})/',
                function ($match) {
                    return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
                },
                $str
            );
        }

        return $str;
    }
1117042
private static function luhn($str)
    {
        $v   = 0;
        $sum = 0;

        for ($i = 0; $i < strlen($str); $i ++) {
            $v = intval($str[$i]);
            $v *= 2 - ($i % 2);

            if ($v > 9) {
                $v -= 9;
            }

            $sum += $v;
        }

        return intval(ceil($sum / 10) * 10 - $sum);
    }
102203
public static function isRoman(string $str) : bool
    {
        $str    = strtoupper(Parser::replaceRoman($str));
        $ary    = Parser::strToArray($str);
        $result = true;
        foreach ($ary as $key => $value) {
            $code = Mbstring::mb_ord($value);
            if ($code >= 97 && 122) {
                $value = strtoupper($value);
            }
            if (array_key_exists($value, self::$romans)) {
                continue;
            } else {
                $result = false;
                break;
            }
        }
        if ($result) {
            foreach (self::$romans as $key => $value) {
                while (mb_strpos($str, $key) === 0) {
                    $str = mb_substr($str, strlen($key));
                }
            }
            $result = mb_strlen($str) === 0;
        }
        return $result;
    }
783785
public static function check($str) {

        // Initialize.
        $sum    = 0;
        $length = strlen($str);
        $parity = $length % 2;

        // Get the sum.
        $sum += substr($str, $length - 1);

        // Handle each character.
        for ($i = $length - 2; 0 <= $i; --$i) {

            // Get the digit.
            $digit = intval(substr($str, $i, 1));

            // Check the parity.
            if ($parity === $i % 2) {
                $digit *= 2;
            }
            if (9 < $digit) {
                $digit -= 9;
            }

            // Add the digit.
            $sum += $digit;
        }

        // Return.
        return 0 === $sum % 10;
    }
98337
public static function int($str)
    {
        if(is_array($str)){
            foreach($str as $key=>$val){
                $str[$key] = self::int($val);
            }
            return $str;
        }
        return preg_replace('/[^0-9]/', '', $str);
    }