Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OutputRules.php

function 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 &amp;, no breaking space unicode characters converted to &nbsp;, when in attribute mode the " should be converted to &quot;, and when not in attribute mode the < and > should be converted to &lt; and &gt;.

Parameters

string $text Text to escape.:

bool $attribute True if we are escaping an attrubute, false otherwise.:

See also

http://www.w3.org/TR/2013/CR-html5-20130806/syntax.html#escapingString

3 calls to OutputRules::escape()
HtmlSerializerRules::escape in core/lib/Drupal/Component/Utility/HtmlSerializerRules.php
Escape test.
HtmlSerializerRules::escape in core/lib/Drupal/Component/Utility/HtmlSerializerRules.php
Escape test.
OutputRules::enc in vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php
Encode text.
1 method overrides OutputRules::escape()
HtmlSerializerRules::escape in core/lib/Drupal/Component/Utility/HtmlSerializerRules.php
Escape test.

File

vendor/masterminds/html5/src/HTML5/Serializer/OutputRules.php, line 531

Class

OutputRules
Generate the output html5 based on element rules.

Namespace

Masterminds\HTML5\Serializer

Code

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(
            '"' => '&quot;',
            '&' => '&amp;',
            " " => '&nbsp;',
        );
    }
    else {
        $replace = array(
            '<' => '&lt;',
            '>' => '&gt;',
            '&' => '&amp;',
            " " => '&nbsp;',
        );
    }
    return strtr($text, $replace);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal