protected function OutputRules::escape 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::escape()
Escape test.
According to the html5 spec section 8.3 Serializing HTML fragments, text within tags that are not style, script, xmp, iframe, noembed, and noframes need to be properly escaped.
The & should be converted to &, no breaking space unicode characters converted to , when in attribute mode the " should be converted to ", and when not in attribute mode the < and > should be converted to < and >.
Parameters
string $text: text to escape.
boolean $attribute: True if we are escaping an attrubute, false otherwise
See also
http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#escapingString
1 call to OutputRules::escape()
- OutputRules::enc in vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php - Encode text.
File
- vendor/
masterminds/ html5/ src/ HTML5/ Serializer/ OutputRules.php, line 527 - The rules for generating output in the serializer.
Class
- OutputRules
- Generate the output html5 based on element rules.
Namespace
Masterminds\HTML5\SerializerCode
protected function escape($text, $attribute = false) {
// Not using htmlspecialchars because, while it does escaping, it doesn't
// match the requirements of section 8.5. For example, it doesn't handle
// non-breaking spaces.
if ($attribute) {
$replace = array(
'"' => '"',
'&' => '&',
" " => ' ',
);
}
else {
$replace = array(
'<' => '<',
'>' => '>',
'&' => '&',
" " => ' ',
);
}
return strtr($text, $replace);
}