Escape::escapeAttrChar PHP Method

escapeAttrChar() protected static method

Callback function for preg_replace_callback() that applies HTML attribute escaping to all matches.
protected static escapeAttrChar ( array $matches ) : mixed
$matches array
return mixed Unicode replacement if character is undefined in HTML, named HTML entity if available (only those that XML supports), upper hex entity if a named entity does not exist or entity with the &#xHH; format if ASCII value is less than 256.
    protected static function escapeAttrChar($matches)
    {
        $char = $matches[0];
        if (static::charIsUndefined($char)) {
            return '�';
        }
        $dec = hexdec(bin2hex($char));
        $namedEntities = array(34 => '"', 38 => '&', 60 => '<', 62 => '>');
        if (isset($namedEntities[$dec])) {
            return $namedEntities[$dec];
        }
        if ($dec > 255) {
            return sprintf('&#x%04X;', $dec);
        }
        return sprintf('&#x%02X;', $dec);
    }