String.escapeHTML

Syntax

PP.String.escapeHTML(text: String);

Parameters

text. Text to escape.

Description

The escapeHTML static method escapes characters of HTML markup in specified string.

Comments

This method returns a String-type value.

Use the PP.String.unescapeHTML method to unescape control characters.

NOTE. This method replaces outdated PP.escapeHTML.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Determine the string that contains control characters, escape and unescape HTML markup characters, and also escape characters of regular expressions:

// Determine a source string with controlling characters
var sourceStr = "<div class=\"mark\">12</div>"
console.log("Source string: " + sourceStr);
// Escape HTML markup characters
var escapeStr = PP.String.escapeHTML(sourceStr);
console.log("String with escaped HTML markup characters: " + escapeStr);
// Unescape HTML markup characters
var unescapeStr = PP.String.unescapeHTML(escapeStr);
console.log("String with unescaped HTML markup characters: " + unescapeStr);
// Escape special characters of regular expressions
var escapeRegExpStr = PP.String.escapeRegExp(sourceStr);
console.log("String with escaped special characters of regular expressions: " + escapeRegExpStr);

After executing the example the browser console displays a source string that contains control characters, then its view that contains escaped and unescaped HTML markup characters, and also escaped special characters of regular expressions:

Source string: <div class="mark">12</div>

String with escaped HTNL markup characters: &lt;div class="mark"&gt;12&lt;/div&gt;

String with unescaped HTML markup characters: <div class="mark">12</div>

String with escaped special characters of regular expressions: <div\ class="mark">12</div>

See also:

PP