Tries to detect format of $str (json or ser).

@param  string $str   - JSON encoded or PHP serialized data.
@return string 'json' | 'ser', or FALSE on failure to detect format.
9578
protected static function serjstype($str)
    {
        $c = substr($str, 0, 1);
        if ('N;' === $str || strpos('sibadO', $c) !== false && substr($str, 1, 1) === ':') {
            $type = 'ser';
        } else {
            $l = substr($str, -1);
            if ('{' == $c && '}' == $l || '[' == $c && ']' == $l) {
                $type = 'json';
            } else {
                $type = false; // Unknown
            }
        }
        return $type;
    }
1306324
public static function strrev(&$str) {
		cast::string($str, true);

		if (! $str) {
			return false;
		}

		\preg_match_all('/./us', $str, $arr);
		$str = \implode('', \array_reverse($arr[0]));

		return true;
	}
1019111
protected static function str2bits($str) 
    {
        $bits  = '';
        $total = strlen($str);

        $i = -1;
        while (++$i < $total) {
            $char = $str[$i];
            $pos  = strpos(self::$_encode, $char);

            if ($pos !== false) {
                $bits .= substr(self::$_binary, $pos*5, 4);
            } else {
                $int   = ord($char);
                $bits .= '1'.substr(self::$_bin, (int)($int/16)*5, 4);
                $bits .= substr(self::$_bin, ($int%16)*5, 4);
            }
        }

        // Complete nibbel
        $add   = strlen($bits) % 4;
        $bits .= str_repeat('0', $add);

        return $bits;
    }
1182403
public static function strrev($str)
    {
        $result = '';
        $strLen = static::length($str);

        if (!$strLen) {
            return $result;
        }

        for ($i = $strLen - 1; $i >= 0; $i--) {
            $result .= static::substr($str, $i, 1);
        }

        return $result;
    }
635070
public static function decode(String $str) : String
    {
        return preg_replace
        (
            array_keys(self::$scriptTagCharsDecode), 
            array_values(self::$scriptTagCharsDecode), 
            $str
        );
    }
199318
public static function encode(String $str) : String
    {
        return str_replace(array_keys(self::$phpTagChars), array_values(self::$phpTagChars), $str);
    }
534510
public static function json($str, bool $pretty=true) {
		ref\format::json($str, $pretty);
		return $str;
	}
1320007
public function str2bin(string $str):string {
		$chrs = unpack('C*', $str);

		return vsprintf(str_repeat('%08b', count($chrs)), $chrs);
	}
292707
function encode($str) {
		return @htmlspecialchars($str,$this->hive['BITMASK'],
			$this->hive['ENCODING'])?:$this->scrub($str);
	}
1110372
public static function toAscii(string $str) : string
    {
        $clean = preg_replace('/[^a-zA-Z0-9\.\/_|+ -]/', '', $str);
        $clean = strtolower(trim($clean, '-'));
        $clean = preg_replace('/[\/_|+ -]+/', '-', $clean);

        return $clean;
    }
153603
public static function Format ($str = '', array $args = []) {
		foreach ($args as $key => $value) {
			$pos = strpos($str, '{'.$key.'}');
			if ($pos !== FALSE)
				$str = substr($str, 0, $pos) . $value . substr($str, $pos + strlen($key) + 2);
		}
		return $str;
	}
970740
public static function isNumberStr($str)
    {
        return !is_resource($str) && !is_array($str) && !is_object($str) && (is_int($str) || is_numeric($str) || preg_match('/^\d*$/', $str));
    }
170616
protected function sessionDecode($str)
    {
        $type = ini_get('session.serialize_handler');
        if ($type === 'php') {
            $this->setSessionState($this->unserializePHP($str));
            return true;
        }
        if ($type === 'php_binary') {
            $this->setSessionState(igbinary_unserialize($str));
            return true;
        }
        return false;
    }
922250
public static function toBoolean($str)
    {
        if (!is_string($str)) {
            $str = strval($str);
        }

        $str = strtolower($str);
        return self::STRING_TO_BOOL_MAP[$str] ?? null;
    }
186785
public function clean_string($str)
    {
        if ($this->is_ascii($str) === FALSE) {
            if (MB_ENABLED) {
                $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
            } elseif (ICONV_ENABLED) {
                $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
            }
        }

        return $str;
    }
529243
public function find($str) {
        while ($line = $this->recvLine()) {
            if (preg_match("/{$str}/", $line, $matches)) {
                return $matches[0];
            }
        }
        return false;
    }
224323
public function isEncoded($str) {
		$this->decoded = $this->_decode($str);

		if ($this->decoded !== false) {
			return true;
		}
		return false;
	}