protected function OutputRules::enc in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php \Masterminds\HTML5\Serializer\OutputRules::enc()
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.
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.
Parameters
string $text: text to encode.
boolean $attribute: True if we are encoding an attrubute, false otherwise
Return value
string The encoded text.
See also
http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#named-character-... True encoding will turn all named character references into their entities.
2 calls to OutputRules::enc()
- OutputRules::attrs in vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php - OutputRules::text in vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php - Write a text node.
File
- vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php, line 488 - The rules for generating output in the serializer.
Class
- OutputRules
- Generate the output html5 based on element rules.
Namespace
Masterminds\HTML5\SerializerCode
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);
}
else {
return strtr($text, \Masterminds\HTML5\Serializer\HTML5Entities::$map);
}
}