Convert an HTML string to entities.

@param string $value

@return string
11290
public function entities($value)
    {
        if (is_array($value)) {
            $newValue = array();
            foreach ($value as $key => $val) {
                $newValue[$key] = htmlentities($val, ENT_QUOTES, 'UTF-8', false);
            }

            return $newValue;
        }

        return htmlentities($value, ENT_QUOTES, 'UTF-8', false);
    }
1340187
private static function getConvertedXmlValue($value)
    {
        $value = (string) $value; // convert from simplexml to string
        // handle booleans specially
        $lwr = strtolower($value);
        if ($lwr === "false") {
            $value = false;
        } elseif ($lwr === "true") {
            $value = true;
        }

        return $value;
    }
1053917
public static function convertString($value)
    {
        if (\strpos($value, '\\') === false) {
            return \substr($value, 1, -1);
        }

        if ($value[0] === "'") {
            return \strtr(\substr($value, 1, -1), ['\\\\' => '\\', '\\\'' => '\'']);
        }

        $value = \substr($value, 1, -1);

        return \preg_replace_callback(
            '/\\\(n|r|t|v|e|f|\$|"|\\\|x[0-9A-Fa-f]{1,2}|u{[0-9a-f]{1,6}}|[0-7]{1,3})/',
            function ($match) {
                switch ($match[1][0]) {
                    case 'n':
                        return "\n";
                    case 'r':
                        return "\r";
                    case 't':
                        return "\t";
                    case 'v':
                        return "\v";
                    case 'e':
                        return "\e";
                    case 'f':
                        return "\f";
                    case '$':
                        return '$';
                    case '"':
                        return '"';
                    case '\\':
                        return '\\';
                    case 'x':
                        return \chr(\hexdec(\substr($match[0], 1)));
                    case 'u':
                        return Strings::chr(\hexdec(\substr($match[0], 1)));
                    default:
                        return \chr(\octdec($match[0]));
                }
            },
            $value
        );
    }
212830
private function _escape($value, $htmlEntities = false)
    {
        if (get_magic_quotes_gpc()) {
            if ($htmlEntities) {
                return htmlspecialchars($value);
            }

            return $value;
        }

        if (is_array($value)) {
            return array_map(function ($n) use ($htmlEntities) {
                $val = stripslashes($n);

                if ($htmlEntities) {
                    return htmlspecialchars($val);
                }

                return $val;
            }, $value);
        }
        $val = stripslashes($value);

        if ($htmlEntities) {
            return htmlspecialchars($val);
        }

        return $val;
    }
976542
public function extract($value)
    {
        if (is_null($value)) {
            return $value;
        }

        $entityValues = $this->getHydratorForEntity($value)->extract($value);
        $entityMetadata = $this->getMetadataMap()[ClassUtils::getRealClass(get_class($value))];

        $link = new Link('self');
        $link->setRoute($entityMetadata['route_name']);
        $link->setRouteParams([
            $entityMetadata['route_identifier_name'] => $entityValues[$entityMetadata['entity_identifier_name']]
        ]);

        $linkCollection = new LinkCollection();
        $linkCollection->add($link);

        $halEntity = new HalEntity(new stdClass());
        $halEntity->setLinks($linkCollection);

        return $halEntity;
    }
1193989
private function decorateStringValue(string $value) : string
    {
        if ($value === '@this'){
            return "\$c";
        }
    
        if (preg_match('/^@id:(.*)$/s',$value,$matches)){
            $id = trim($matches[1]);
            return "\$c['" . self::escapeSingleQuote($id) . "']";
        }
    
        if (preg_match('/^@resolve:(.*)$/s',$value,$matches)){
            $target = trim($matches[1]);
            return "\$c[\$c->resolve('" . self::escapeSingleQuote($target) . "')]";
        }
    
        if (preg_match('/^@func:(.*)$/s',$value,$matches)){
            $func = trim($matches[1]);
            $this->validateCallable($func);
            return $func;
        }
        
        if (preg_match('/^@int:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateInteger($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@float:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateFloat($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@bool:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateBool($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@json:(.*)$/s',$value,$matches)){
            $value = trim($matches[1]);
            $value = $this->validateJson($value);
            return $this->decorateValue($value);
        }
    
        if (preg_match('/^@env:(.*)$/s',$value,$matches)){
            $id = trim($matches[1]);
            return "(\$_ENV['" . self::escapeSingleQuote($id) . "'] ?? null)";
        }
    
        return "'" . self::escapeSingleQuote($value) . "'";
    }
70384
public static function convertToPhp($value)
    {
        if (is_string($value)) {
            return Translatable::createFromOriginalString($value);
        }

        if (is_array($value)) {
            return Translatable::createFromTranslations($value);
        }

        return null;
    }
982042
static public function formatSearch($value)
    {
        $value = static::filter_xss($value);
        $value = static::html_entities($value);
        $value = str_replace('&lt;', '', $value);
        $value = str_replace('&gt;', '', $value);
        $value = static::sql_encode($value);
        $value = trim($value);
        
        return $value;
    }
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)
        );
    }
345162
protected function serializeValue($value)
    {
        $serialized = var_export($value, true);
        if ($serialized === 'NULL') {
            $serialized = strtolower($serialized);
        }

        return $serialized;
    }
1246256
public function parseValue($value)
    {
        if (is_array($value)) {
            array_walk_recursive($value, [$this, 'doHtmlspecialchars']);
        } else {
            $value = $this->doHtmlspecialchars($value);
        }

        return parent::parseValue($value);
    }
881602
public function encodeValue($value)
    {
        if ($this->urlEncode == self::RFC_3986) {
            return rawurlencode($value);
        } elseif ($this->urlEncode == self::FORM_URLENCODED) {
            return urlencode($value);
        } else {
            return (string) $value;
        }
    }
652203
private static function sanitizeString($value)
    {
        // $_GET and $_REQUEST already urldecode()'d
        // decode
        // note: before php 5.2.7, htmlspecialchars() double encodes &#x hex items
        $value = html_entity_decode($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');

        $value = self::sanitizeNullBytes($value);

        // escape
        $tmp = @htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');

        // note: php 5.2.5 and above, htmlspecialchars is destructive if input is not UTF-8
        if ($value != '' && $tmp == '') {
            // convert and escape
            $value = utf8_encode($value);
            $tmp = htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
            return $tmp;
        }
        return $tmp;
    }
1260366
private static function encodeValueXml($value)
    {
        if ($value instanceof \DateTime) {
            return $value->format('Y-m-d\TH:i:s.000\Z');
        }
        else if (is_bool($value)){
            return $value ? 'true' : 'false';
        } else {
            return $value;
        }
    }
724480
public static function convertFromUrlencodeSqlComment($value)
    {
        if (preg_match_all('/(?:\%23.*?\%0a)/im',$value,$matches)){
            $converted = $value;
            foreach($matches[0] as $match){
                $converted = str_replace($match,' ',$converted);
            }
            $value .= "\n" . $converted;
        }
        return $value;
    }
283766
private function stringifyValue($value)
    {
        switch (true) {
            case $value === null:
                $value = 'NULL';
                break;
            case ($value instanceof \DateTime):
                $value = $value->format(DATE_RFC822);
                break;
            case ($value instanceof StringableInterface):
                $value = $value->toString();
                break;
            case ($value instanceof ArrayableInterface):
                $value = sprintf('Arrayable::%s (%s)', (new \ReflectionObject($value))->getShortName(),
                    $this->stringifyValue($value->toArray()));
                break;
            case is_scalar($value):
            case method_exists($value, '__toString'):
                $value = (string) $value;
                break;
            case is_object($value):
                $value = sprintf('Object (%s)', get_class($value));
                break;
            case is_array($value):
                $value = sprintf('Array (%s)', implode(', ', array_map([$this, 'stringifyValue'], $value)));
                break;
        }
        
        return $value;
    }
459476
protected function resolveQueueableEntity($value)
	{
		if (is_string($value) && Str::startsWith($value, '::entity::')) {
			list($marker, $type, $id) = explode('|', $value, 3);

			return $this->getEntityResolver()->resolve($type, $id);
		}

		return $value;
	}