Xbasic

*HTML_ESCAPE Function

Syntax

Encoded_Text as C = *HTML_ESCAPE(C text[,C flags])

Arguments

Encoded_Text

Text encoded for HTML use.

text

Text as Displayed on a monitor.

flags

Optional. Default = "". HTML encoding rules. Character

"" = Escape all characters with values above 127 and some of the other low punctuation characters (i.e. like dash & back-quote).
"B" = encode space characters as non-breaking spaces ()
"S" = short list of characters to encode. Only escape & , ' , " , < ,>characters.
"SC" = encode with hexadecimal values (used on command lines)
"Q" = an alternative to the "S" option to omit encoding the single quote character.
"E" = Do not encode encoded unicode characters (e.g. &#x0* pattern). If you use the 'E' flag, the '&' in the text that matches the encoded unicode character pattern is not encoded.
"UTF8" = Encode special characters as well as UTF8 encoded high order characetrs.
"UTF8H" = Encode only UTF8 encoded high order characetrs.

Description

The *HTML_ESCAPE() function encodes text for HTML use. Escape HTML characters, flags - 'B'lanks translated, 'S'hort list (&,",',<,>), 'Q'uotes excluded short (&,",<,>), 'D'ouble quotes only("), 'L' - label format.

Examples 

This conversion uses no flags.

? *html_escape("This is <...> text")
= "This is < > text"

This conversion encodes space characters as non-breaking spaces.

? *html_escape("This is <...> text","b")
= "This is < > text"

This conversion defines a short list of characters to encode

? *html_escape("This is <...> text","s")
= "This is <...> text"

SC - encode with hexadecimal values

? *html_escape("This is <...> text","sc")
= "This#20is#20<#FA>#20text"

UTF8 - Treat high order characters as UTF8 encoding, and escape them.

' chinese characters for china (Middle + Kingdom)
dim china as c = *unicode_to_utf8(20013)+*unicode_to_utf8(22269)
?*html_escape(china,"utf8")
= "&#x4e2d;&#x56fd;"

UTF8H - If you wanted to keep the special HTML characters, but convert any high order characters from utf8 encoded characters to escaped HTML characters. This is useful for processing templates with high order characters so that code page for the html is not an issue.

' chinese characters for china (Middle + Kingdom)
dim china as c = "<b>"+*unicode_to_utf8(20013)+*unicode_to_utf8(22269)+"</b>"
?*html_escape(china,"utf8")
= "&lt;b&gt;&#x4e2d;&#x56fd;&lt;/b&gt;"
?*html_escape(china,"utf8h")
= "<b>&#x4e2d;&#x56fd;</b>"

See Also