Minify string

@param string $str
@return string
488038
public static function minify($str)
    {
        $matchesCode = $matchesPre  = $matches     = [];

        preg_match_all('/<code.*?>(.*?)<\/code>/mis', $str, $matchesCode);
        preg_match_all('/<pre.*?>(.*?)<\/pre>/mis', $str, $matchesPre);
        $matches = array_merge($matchesCode[1], $matchesPre[1]);
        foreach ($matches as $match) {
            $str = str_replace($match, '$'.md5($match), $str);
        }
        $str = preg_replace(['/<!--(.*)-->/Uis', "/[[:blank:]]+/"], ['', ' '],
            str_replace(["\n", "\r", "\t"], '', $str));
        foreach ($matches as $match) {
            $str = str_replace('$'.md5($match), $match, $str);
        }
        return $str;
    }
218385
private static function MinifyCSS($sStr){
            $sStr = preg_replace('!/\*.*?\*/!s','', $sStr);
            $sStr = preg_replace('/\n\s*\n/',"\n", $sStr);
            $sStr = preg_replace('/[\n\r \t]/',' ', $sStr);
            $sStr = preg_replace('/ +/',' ', $sStr);
            $sStr = preg_replace('/ ?([,:;{}]) ?/','$1',$sStr);
            $sStr = preg_replace('/;}/','}',$sStr);
            return $sStr;
        }
690745
public function prepend($str)
    {
        $value = $this->val();
        $this->val($str . $value);

        return $this;
    }
161508
public static function replaceSpecialChars($str)
    {
        return preg_replace(array_keys(self::$specialCharsArray), array_values(self::$specialCharsArray), $str);
    }
285666
private function toCamelCase($str)
    {
        // Split string in words.
        $words = preg_split('/[-_]/', strtolower($str)); //explode('_', strtolower($str));

        $return = '';
        foreach ($words as $word) {
            $return .= ucfirst(trim($word));
        }

        return $return;
    }
613860
public static function minify($string, $noSpace = false)
    {
        $string = preg_replace("/\s+/", ' ', $string);
        return $noSpace ? str_replace(' ', '', $string) : $string;
    }
71038
public function min($str, $length)
    {
        return $this->notempty($str) && strlen(trim($str)) >= $length;
    }
796493
public static function toCamelCase($str)
    {
        $str = ucwords(str_replace('_', ' ', $str));
        $str = str_replace(' ', '', lcfirst($str));
        return $str;
    }
965858
public static function minify($expr)
	{
		$old     = $expr;
		$strings = [];

		// Trim the surrounding whitespace then temporarily remove literal strings
		$expr = preg_replace_callback(
			'/"[^"]*"|\'[^\']*\'/',
			function ($m) use (&$strings)
			{
				$uniqid = '(' . sha1(uniqid()) . ')';
				$strings[$uniqid] = $m[0];

				return $uniqid;
			},
			trim($expr)
		);

		if (preg_match('/[\'"]/', $expr))
		{
			throw new RuntimeException("Cannot parse XPath expression '" . $old . "'");
		}

		// Normalize whitespace to a single space
		$expr = preg_replace('/\\s+/', ' ', $expr);

		// Remove the space between a non-word character and a word character
		$expr = preg_replace('/([-a-z_0-9]) ([^-a-z_0-9])/i', '$1$2', $expr);
		$expr = preg_replace('/([^-a-z_0-9]) ([-a-z_0-9])/i', '$1$2', $expr);

		// Remove the space between two non-word characters as long as they're not two -
		$expr = preg_replace('/(?!- -)([^-a-z_0-9]) ([^-a-z_0-9])/i', '$1$2', $expr);

		// Remove the space between a - and a word character, as long as there's a space before -
		$expr = preg_replace('/ - ([a-z_0-9])/i', ' -$1', $expr);

		// Remove the spaces between a number and the div operator and the next token
		$expr = preg_replace('/((?:^|[ \\(])\\d+) div ?/', '$1div', $expr);

		// Remove the space between the div operator the next token
		$expr = preg_replace('/([^-a-z_0-9]div) (?=[$0-9@])/', '$1', $expr);

		// Restore the literals
		$expr = strtr($expr, $strings);

		return $expr;
	}
1024539
public static function encode(String $str) : String
    {
        return preg_replace
        (
            array_keys(self::$scriptTagChars), 
            array_values(self::$scriptTagChars), 
            $str
        );
    }
541557
public static function toCamelCase(string $str): string
    {
        $str = trim($str);
        $fn = function($arg) {
            list($match, $char) = $arg;
            $ret = str_replace($char, "", $match);
            return strtoupper($ret);
        };
        return preg_replace_callback("~( |_|-){1,}[A-Za-z]~", $fn, $str);
    }
530214
public static function shorten($str, $length = 100, $end = '&#8230;')
    {
        $data = $str;

        if (strlen($data) > $length)
        {
            $data = trim($data);
            $data = \substr($data, 0, $length);
            $rev  = \strrev($data);
            $pos  = \strpos($rev, ' ');
            $data = \substr($data, 0, -$pos);
            $data .= trim($end);
        }

        return $data;
    }
1161991
public function preProcessString($str)
    {
        $str = str_replace("<?php", "", $str);
        $str = str_replace("<?", "", $str);
        $str = str_replace("?>", "", $str);
        $str = str_replace("'", "\x22", $str);

        $str = trim($str);

        return $str;
    }
1177467
public function slugify($str)
    {
        $str = mb_strtolower(trim($str));
        $str = str_replace(array('å','ä','ö'), array('a','a','o'), $str);
        $str = preg_replace('/[^a-z0-9-]/', '-', $str);
        $str = trim(preg_replace('/-+/', '-', $str), '-');
        return $str;
    }
662632
private function toNamespace($str) {
        $stringParts = preg_split('/_+/', $str);

        foreach($stringParts as $key => $stringPart){
            $stringParts[$key] = ucfirst(strtolower($stringPart));
        }
        return implode('\\', $stringParts) . '\\';
    }
668183
private function append_str($str)
  { 
    $this->check_closed(); 
    $this->string_buffer .= $str; 
    $len = strlen($str); 
    $this->current_index += $len; 
    return $len; 
  }
513746
protected static function ourStrlen($str)
    {
        // Premature optimization: cache the function_exists() result
        static $exists = null;
        if ($exists === null) {
            $exists = \function_exists('\\mb_strlen');
        }

        // If it exists, we need to make sure we're using 8bit mode
        if ($exists) {
            return \mb_strlen($str, '8bit');
        }
        return \strlen($str);
    }