Escape HTML characters amd entities.

@param string $string
@param int $flags
@return string
766414
public function escape($string, $flags = null) {
        if ($flags === null) {
            $flags = ENT_QUOTES;
        }

        $flags |= ENT_SUBSTITUTE;

        return htmlentities($string, $flags, 'UTF-8', false);
    }
935695
public function replaceTokens($string)
    {
        foreach ($this->getTokenNames($string) as $token) {
            $string = str_replace("{{$token}}", $this->getTokenValue($token), $string);
        }
        
        return $string;
    }
48971
public static function escape($string, $context = 'html')
    {
        $method = 'escape'.ucfirst($context);

        if(!method_exists(__CLASS__, $method)) {
            throw new \InvalidArgumentException(sprintf('Cannot escape to: %s. Unknow context.', $context));
        }

        return static::$method($string);
    }
199964
protected function escape(string $string): string
    {
        return htmlspecialchars($string, ENT_QUOTES | ENT_IGNORE, $this->encoding);
    }
926927
public function escape($string)
    {
        if (defined('ENT_DISALLOWED')) {
            // 'ENT_DISALLOWED' ensures that invalid characters in the given document type are replaced.
            // Otherwise control characters like a vertical tab "\v" will make the XML document unreadable by the XML processor
            // @link https://github.com/box/spout/issues/329
            $replacedString = htmlspecialchars($string, ENT_NOQUOTES | ENT_DISALLOWED);
        } else {
            // We are on hhvm or any other engine that does not support ENT_DISALLOWED.
            //
            // @NOTE: Using ENT_NOQUOTES as only XML entities ('<', '>', '&') need to be encoded.
            //        Single and double quotes can be left as is.
            $escapedString =  htmlspecialchars($string, ENT_NOQUOTES);

            // control characters values are from 0 to 1F (hex values) in the ASCII table
            // some characters should not be escaped though: "\t", "\r" and "\n".
            $regexPattern = '[\x00-\x08' .
                            // skipping "\t" (0x9) and "\n" (0xA)
                            '\x0B-\x0C' .
                            // skipping "\r" (0xD)
                            '\x0E-\x1F]';
            $replacedString = preg_replace("/$regexPattern/", '�', $escapedString);
        }

        return $replacedString;
    }
1370314
public static function escape($string)
    {
        // when we have a numeric string only, nothing needs to be done
        if (is_numeric($string)) {
            return $string;
        }

        // when no whitespaces are in the query we can also just escape the special characters
        if (preg_match('/\W/', $string) != 1) {
            return static::escapeSpecialCharacters($string);
        }

        // when there are no quotes inside the query string we can also just escape the whole string
        $hasQuotes = strrpos($string, '"') !== false;
        if (!$hasQuotes) {
            return static::escapeSpecialCharacters($string);
        }

        $result = static::tokenizeByQuotesAndEscapeDependingOnContext($string);

        return $result;
    }
487419
public function escape($string)
    {
        if(is_string($string)) {
            $string = htmlspecialchars($string, ENT_COMPAT | ENT_SUBSTITUTE, 'UTF-8', false);
        }

        return $string;
    }
1057143
public function encodeHtmlEntities($string)
    {
        $string = mb_convert_encoding($string, 'UTF-32', 'UTF-8');
        $t = unpack('N*', $string);
        $t = array_map(static function($n) {
            return "&#$n;";
        }, $t);

        return implode('', $t);
    }
687368
public static function html($string) {

        if(null === $string) {
            return '';
        }

		if(true === is_numeric($string)) {
    		return $string;
    	}

		if(false === is_string($string)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($string)), E_USER_ERROR);
		}

        return htmlspecialchars($string, static :: $flags, static :: getEncoding());
    }
912008
protected function escape($string)
    {
        $string = HTMLPurifier_Encoder::cleanUTF8($string);
        $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
        return $string;
    }
149992
public static String escape(String string) {
        if (isEmpty(string)) return "";
        StringBuilder sb = new StringBuilder();
        char[] chars = string.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (i == chars.length - 1 || chars[i] != '\r' || chars[i + 1] != '\n') {
                sb.append(escape(chars[i]));
            }
        }
        return sb.toString();
    }
472266
private function escape_token_string(&$text, $token) {
        $text = str_replace("~".$token, $this->protect($token), $text);
    }
1303744
public function escape($string)
    {
        $string = mb_convert_encoding($string, 'UTF-8', 'UTF-8');
        $string = str_replace('{{', '', $string);
        $string = str_replace('}}', '', $string);

        return htmlentities($string, ENT_QUOTES, 'UTF-8');
    }
452045
public static function escapeCss($string)
    {
        if ($string !== '' && !ctype_digit($string))
        {
            $matcher = function($matches)
            {
                $chr = $matches[0];

                if (strlen($chr) !== 1)
                {
                    $chr = static::convertEncoding($chr, 'UTF-16BE', 'UTF-8');
                    $ord = hexdec(bin2hex($chr));
                }
                else $ord = ord($chr);

                return sprintf('\\%X ', $ord);
            };

            $string = preg_replace_callback('/[^a-z0-9]/iSu', $matcher, $string);
        }


        return $string;
    }
268532
public function escapeUrl($string, $encoding = 'utf-8') {
		
		$current = Escape :: getEncoding();
		Escape :: setEncoding($encoding);
		$result =  Escape :: url($string);
		Escape :: setEncoding($current);

		return $result;
	}
31408
static public function escapeSymbols($string, $symbols)
    {
        if (!is_array($symbols)) {
            $symbols = array($symbols);
        }

        $len = mb_strlen($string, 'UTF-8');
        $returnValue = '';

        for ($i = 0; $i < $len; $i++) {
            $char = mb_substr($string, $i, 1); // get a multi-byte char.
            if (in_array($char, $symbols) === true) {

                // Check escaping.
                // If the amount of preceding backslashes is odd, it is escaped.
                // If the amount of preceding backslashes is even, it is not escaped.
                if (static::getPrecedingBackslashesCount($string, $i) % 2 === 0) {
                    // It is not escaped, so ecape it.
                    $returnValue .= '\\';
                }
            }

            $returnValue .= $char;
        }

        return $returnValue;
    }
523795
private static function PrepareRegexFlags( $flagString )
	{
		// The flag string can only contain s,m,i and/or x
		$result = preg_match( "/[^smix]+/", $flagString);
		if ( $result )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FORX0001", Resources::InvalidRegularExpr, "$flagString" );
		}

		return $flagString;
	}