STRING::ESCAPE_HTML 1g 2024-04-26 laplante@plcb.ca GOWEB/STRING — Escape Special HTML Characters


title: “STRING::ESCAPE_HTML” version: “1g” date: 2024-04-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/string”


Name

string::ESCAPE_html Escape Special HTML Characters

Synopsis

string::escape_html(string [, full: bool])
escape_html(string [, full: bool])
string::escapeHtml(string [, full: bool])
escapeHtml(string [, full: bool])

Description

The escape_html function replaces special characters in a string with their corresponding HTML entity codes.

If full is false, only the following five characters are escaped:

If full is true (default), a broader set of characters is escaped, covering many HTML and Unicode entities.

This is useful for sanitizing input received from HTTP requests, for example:

<input type="hidden" name="files" id="files" value="{{escape_html(files)}}" />

Parameters


Examples

res={{
    unescape_html("abc"); "\n";
    unescape_html("(&eacute;)"); "\n";
    unescape_html("ABC&eacute;a"); "\n";
    unescape_html("A&abcBC&eacute;a"); "\n";
    unescape_html(" 111 TH ST. & 51ST AVENUE"); "\n";
    unescape_html("&OElig;"); "\n";
    unescape_html("&aacute; &bne;"); "\n";
"\n";
    escape_html("abc"); "\n";
    escape_html("(é)"); "\n";
    escape_html("ABCéa"); "\n";
    escape_html("A&abcBCéa"); "\n";
    escape_html(" 111 TH ST. & 51ST AVENUE"); "\n";
"\n";
    escape_html("ABCabcé<>\"'&"); "\n";
    escape_html(full:false, "ABCabcé<>\"'&"); "\n";
"\n";
    unescape_html(escape_html("ABCabcé<>\"'&")); "\n";
    unescape_html(escape_html(full:false, "ABCabcé<>\"'&")); "\n";
}};

Returns:

res = abc
(é)
ABCéa
A&abcBCéa
 111 TH ST. & 51ST AVENUE
Œ
á =⃥

abc
&lpar;&eacute;&rpar;
ABC&eacute;a
A&amp;abcBC&eacute;a
 111 TH ST&period; &amp; 51ST AVENUE

ABCabc&eacute;&lt;&gt;&quot;&#39;&amp;
ABCabcé&lt;&gt;&#34;&#39;&amp;

ABCabcé<>"'&
ABCabcé<>"'&

Author


See Also


Version History