Escape a string

By default the function uses htmlspecialchars to escape the string

@param string $string String to to be escape
@return string Escaped string
487419
public function escape($string)
    {
        if(is_string($string)) {
            $string = htmlspecialchars($string, ENT_COMPAT | ENT_SUBSTITUTE, 'UTF-8', false);
        }

        return $string;
    }
189492
private function escape($value)
    {
        if (1 !== preg_match($this->escapeCharacterPattern, $value)) {
            return htmlspecialchars($value, ENT_QUOTES);
        }

        return str_replace(
            $this->controlCharacters, $this->escapeCharacters, htmlspecialchars($value, ENT_QUOTES)
        );
    }
1374154
protected function escapeLike($string)
    {
        $escapedString = addcslashes($string, '\'\\');
        $replace = [
            '\\\\%' => '\\%',
            '\\\\_' => '\\_',
        ];
        $escapedString = str_replace(array_keys($replace), array_values($replace), $escapedString);
        return "'" . $escapedString . "'";
    }
264805
def escape(cls, string):
        

        return ''.join([cls._escapes[c] if cls._needescape(c) else c
                        for c in string.encode('utf8')])
1111902
public static function esc($string)
    {
        Arguments::define(Boa::string())->check($string);

        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
    }
360471
private function _escape($string, $escapeChar)
    {
        if ($escapeChar) {
            $this->buffer = $escapeChar;

            return preg_replace_callback(
                '/\\' . $escapeChar . '(.)' .'/',
                array(&$this, '_escapeBis'),
                $string
            );

        } else {
            return $string;
        }
    }
1340796
protected function _formatString($string)
    {
        $quote = substr($string, 0, 1);
        $string = substr($string, 1, -1);
        if ($quote === '"') {
            $string = stripcslashes($string);
        } else {
            $string = strtr($string, ["\\'" => "'", '\\\\' => '\\']);
        }
        $string = str_replace("\r\n", "\n", $string);

        return addcslashes($string, "\0..\37\\\"");
    }
463785
private static function escape( $string )
	{
		$replace	= array(
			'\\'	=> '\\\\',
			'"'	=> '\"',
			'/'	=> '\/',
			"\b"	=> '\b',
			"\f"	=> '\f',
			"\n"	=> '\n',
			"\r"	=> '\r',
			"\t"	=> '\t',
			"\u"	=> '\u'
			);
		$string	= str_replace( array_keys( $replace ), array_values( $replace ), $string );
		return $string;
	}
506931
public function escapeHtml($string) {
        $string = $this->convertNewlines($string);

        if ($this->getConfig('escapeHtml')) {
            $string = $this->escape($string, ENT_NOQUOTES);
        }

        return $string;
    }
1215061
public function escape($string)
    {
        if (is_string($string)) {
            $func = $this->escape;
            return $func($string);
        }
        return $string;
    }
705602
protected function escapeLatex($string)
	{
		if ($this->_escaper === null) {
			$this->_escaper = new TextToLatex();
		}
		return $this->_escaper->convert($string);
	}
1183324
public static function ucfirst($string)
    {
        switch (static::strlen($string)) {
            case 0:
                return '';
            case 1:
                return static::strtoupper($string);
            default:
                return static::strtoupper(static::substr($string, 0, 1)) . static::substr($string, 1);
        }
    }
29068
private static function containsEscapeCharacters($string)
    {
        $escapeCodePattern = '#' . static::ANSI_ESCAPE_CODE_REGEX . '#';
        $result            = preg_match($escapeCodePattern, $string);

        return (boolean) $result;
    }
794010
public static function escape($string) {
    $escaped_chars = str_split(self::ESCAPED_CHARACTERS);
    $escaped_chars_replace = array_map(function($char) {
      return '\\' . $char;
    }, $escaped_chars);
    $string = str_replace($escaped_chars, $escaped_chars_replace, $string);
    // Ignored whitespace.
    return preg_replace('/\s+/u', ' ', $string);
  }
911416
public function escape_string($str)
    {
        // Prepare one MySQL client connect
        $isFromPool = $this->prepareDB();

        $str = $this->db->real_escape_string($str);

        if ($isFromPool) {
            DBPool::init($this->db_config)->back($this->db);
        } else {
            DBPool::init($this->db_config)->in($this->db);
        }

        return $str;
    }
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');
    }
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());
    }