Returns a string converted to html entities.

@see http://goo.gl/LPhtJ

@param  string $string Value to be encoded

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

        return implode("", $t);
    }
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');
    }
655656
public function literal($string) {
        $string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose . $this->_quoteChar);
        return $string;
    }
966845
public static function stringToValue($string)
	{
		if($string == '')
		{
			return $string;
		}
		if(is_float($string))
		{
			return (float) $string;
		}
		if(is_int($string))
		{
			return (int) $string;
		}
		if(strtolower($string) == 'true')
		{
			return true;
		}
		if(strtolower($string) == 'false')
		{
			return false;
		}
		if(strtolower($string) == 'null')
		{
			return NULL;
		}
		
		return $string;
	}
1036165
public static function stringToArray($string)
    {
        if (!preg_match("@^{.*?}$@", $string)) {
            return $string;
        }
        $parts = explode(',', substr($string, 1, -1));
        foreach ($parts as &$part) {
            $part = self::stringToArray($part);
        }
        return $parts;
    }
548936
public function xml_escape($string) {
        if (!empty($string) && htmlspecialchars($string) != $string) {
            // If the string contains something that looks like the end
            // of a CDATA section, then we need to avoid errors by splitting
            // the string between two CDATA sections.
            $string = str_replace(']]>', ']]]]><![CDATA[>', $string);
            return "<![CDATA[{$string}]]>";
        } else {
            return $string;
        }
    }
226681
public function parseHtml($string)
    {
        return $this->parseSource(
            $string,
            new HtmlDocumentFactory(),
            (new RdfaLiteElementProcessor())->setHtml(true),
            new RdfaLiteContext()
        );
    }
328719
public static function convertToHtmlEntities($string, $encoding)
    {
        if (function_exists('mb_convert_encoding')) {
            return mb_convert_encoding($string, 'HTML-ENTITIES', $encoding);
        }

        if ('UTF-8' !== $encoding) {
            $string = iconv($encoding, 'UTF-8//IGNORE', $string);
        }

        return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'htmlEncodingCallback'], $string);
    }
1065860
public static function textScript($string): string
    {
        $string = strip_tags($string); // otherwise HTML tags show up as latin
        $string = html_entity_decode($string, ENT_QUOTES, 'UTF-8'); // otherwise HTML entities show up as latin
        $string = str_replace([
            '@N.N.',
            '@P.N.',
        ], '', $string); // otherwise unknown names show up as latin
        $pos    = 0;
        $strlen = strlen($string);
        while ($pos < $strlen) {
            // get the Unicode Code Point for the character at position $pos
            $byte1 = ord($string[$pos]);
            if ($byte1 < 0x80) {
                $code_point = $byte1;
                $chrlen     = 1;
            } elseif ($byte1 < 0xC0) {
                // Invalid continuation character
                return 'Latn';
            } elseif ($byte1 < 0xE0) {
                $code_point = (($byte1 & 0x1F) << 6) + (ord($string[$pos + 1]) & 0x3F);
                $chrlen     = 2;
            } elseif ($byte1 < 0xF0) {
                $code_point = (($byte1 & 0x0F) << 12) + ((ord($string[$pos + 1]) & 0x3F) << 6) + (ord($string[$pos + 2]) & 0x3F);
                $chrlen     = 3;
            } elseif ($byte1 < 0xF8) {
                $code_point = (($byte1 & 0x07) << 24) + ((ord($string[$pos + 1]) & 0x3F) << 12) + ((ord($string[$pos + 2]) & 0x3F) << 6) + (ord($string[$pos + 3]) & 0x3F);
                $chrlen     = 3;
            } else {
                // Invalid UTF
                return 'Latn';
            }

            foreach (self::SCRIPT_CHARACTER_RANGES as $range) {
                if ($code_point >= $range[1] && $code_point <= $range[2]) {
                    return $range[0];
                }
            }
            // Not a recognised script. Maybe punctuation, spacing, etc. Keep looking.
            $pos += $chrlen;
        }

        return 'Latn';
    }
921019
protected function encodeString($string)
    {
        // If no encoding value was passed in...
        if ($this->encoding === null) {
            return $string;
        }

        $detect = mb_detect_encoding($string);

        // If the current encoding is already the requested encoding
        if (is_string($detect) && $detect === $this->encoding) {
            return $string;
        }

        // Failed to determine encoding
        if (is_bool($detect)) {
            return $string;
        }

        // Convert it!
        return mb_convert_encoding($string, $this->encoding, $detect);
    }
331926
public static function cleanse(string $string): string
    {
        return trim(
            htmlspecialchars_decode(
                strip_tags(
                    str_replace(['<br>', '<br/>', '<br />'], '\n', $string)
                ),
                ENT_QUOTES
            )
        );
    }
989087
protected function convertString($string)
    {
        $charset = strtolower($this->getCharset());
        if (!in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
            return mb_convert_encoding($string, $charset, 'utf-8');
        }

        return $string;
    }
45105
public static function encode($string)
    {
        return is_null($string) ? self::NULL : strtr($string, self::$encodeMap);
    }
695406
public static function convertCharacterEntitiesToASCII($string, $charset)
    {
        $matches = array();

        if (preg_match_all("/<(.+?)>/si", $string, $matches)) {

            $count = count($matches['0']);

            for ($i = 0; $i < $count; $i++) {
                $string = str_replace(
                    $matches['1'][$i],
                    html_entity_decode($matches['1'][$i], ENT_COMPAT, $charset),
                    $string
                );
            }
        }

        return $string;
    }
86180
public static function encode($string)
    {
        if (is_array($string)) {
            foreach ($string as $k => $substring) {
                $string[$k] = static::encode($substring);
            }
        } else {
            $string = urlencode($string);
        }

        return $string;
    }
655025
public static function fromString( $string )
	{
#		$string		= trim( $string );
		$parts		= explode( "\r\n\r\n", $string );
		$response	= new Net_HTTP_Response;
		while( $part = array_shift( $parts ) )
		{
			$pattern	= '/^([A-Z]+)\/([0-9.]+) ([0-9]{3}) ?(.+)?/';
			if( !preg_match( $pattern, $part ) )
			{
				array_unshift( $parts, $part );
				break;
			}
			if( !$response->headers->getFields() )
				$response	= self::parseHeadersFromString( $part );
		};
		$body	= implode( "\r\n\r\n", $parts );

/*		$encodings	= $response->headers->getField( 'content-encoding' );
		while( $encoding = array_pop( $encodings ) )
		{
			$method	= $encoding->getValue();
			$body	= Net_HTTP_Response_Decompressor::decompressString( $body, $method );
		}*/
		$response->setBody( $body );
		return $response;
	}
83155
protected function fixCharset($string)
    {
        if ('UTF-8' !== $this->getCharset()) {
            $string = mb_convert_encoding($string, $this->getCharset(), 'UTF-8');
        }

        return $string;
    }