STRING::ESCAPE_HTML
1g 2024-04-26 laplante@plcb.ca GOWEB/STRING — Escape Special HTML Characterstitle: “STRING::ESCAPE_HTML” version: “1g” date: 2024-04-26 author: “laplante@plcb.ca” section: “1g” category: “GOWEB/string”
string::ESCAPE_html Escape Special HTML Characters
string::escape_html(string [, full: bool])
escape_html(string [, full: bool])
string::escapeHtml(string [, full: bool])
escapeHtml(string [, full: bool])
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)}}" />
string (string, required) The text to escape.
full (boolean, optional)
If true
(default), escape all supported characters.
If false
, escape only the five standard HTML special characters.
res={{
unescape_html("abc"); "\n";
unescape_html("(é)"); "\n";
unescape_html("ABCéa"); "\n";
unescape_html("A&abcBCéa"); "\n";
unescape_html(" 111 TH ST. & 51ST AVENUE"); "\n";
unescape_html("Œ"); "\n";
unescape_html("á =⃥"); "\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
(é)
ABCéa
A&abcBCéa
111 TH ST. & 51ST AVENUE
ABCabcé<>"'&
ABCabcé<>"'&
ABCabcé<>"'&
ABCabcé<>"'&