src/PowerTools/HTML5/Serializer/OutputRules.php
protected function enc($text, $attribute = false) {

        // Escape the text rather than convert to named character references.
        if (!$this->encode) {
            return $this->escape($text, $attribute);
        }

        // If we are in PHP 5.4+ we can use the native html5 entity functionality to
        // convert the named character references.

        if ($this->hasHTML5) {
            return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false);
        }         // If a version earlier than 5.4 html5 entities are not entirely handled.
        // This manually handles them.
        else {
            return strtr($text, HTML5_Serializer_HTML5Entities::$map);
        }
    }
protected function enc($text, $attribute = false) {

        // Escape the text rather than convert to named character references.
        if (!$this->encode) {
            return $this->escape($text, $attribute);
        }

        // If we are in PHP 5.4+ we can use the native html5 entity functionality to
        // convert the named character references.

        if ($this->hasHTML5) {
            return htmlentities($text, ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES, 'UTF-8', false);
        }         // If a version earlier than 5.4 html5 entities are not entirely handled.
        // This manually handles them.
        else {
            return strtr($text, HTML5_Serializer_HTML5Entities::$map);
        }
    }
protected function enc ( $ text , $ attribute = false ) { // Escape the text rather than convert to named character references. if ( ! $ this -> encode ) { return $ this -> escape ( $ text , $ attribute ) ; } // If we are in PHP 5.4+ we can use the native html5 entity functionality to // convert the named character references. if ( $ this -> hasHTML5 ) { return htmlentities ( $ text , ENT_HTML5 | ENT_SUBSTITUTE | ENT_QUOTES , 'UTF-8' , false ) ; } // If a version earlier than 5.4 html5 entities are not entirely handled. // This manually handles them. else { return strtr ( $ text , HTML5_Serializer_HTML5Entities :: $ map ) ; } }
Encode text.

When encode is set to false, the default value, the text passed in is
escaped per section 8.3 of the html5 spec. For details on how text is
escaped see the escape() method.

When encoding is set to true the text is converted to named character
references where appropriate. Section 8.1.4 Character references of the
html5 spec refers to using named character references. This is useful for
characters that can't otherwise legally be used in the text.

The named character references are listed in section 8.5.

@see http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#named-character-references True encoding will turn all named character references into their entities.
This includes such characters as +.# and many other common ones. By default
encoding here will just escape &'<>".

Note, PHP 5.4+ has better html5 encoding.

@todo Use the Entities class in php 5.3 to have html5 entities.

@param string $text
text to encode.
@param boolean $attribute
True if we are encoding an attrubute, false otherwise

@return string The encoded text.
Encode text .