HTMLENCODE Function
Syntax
Encoded_String as C = HTMLENCODE(input as C [, strict as L])
Arguments
- inputCharacter
The string to be encoded.
- strictLogical
Default = .F.. Indicates whether or not strict encoding should be used. If .F., only the most common characters are substituted with their HTML entity value. If .T., all characters which have HTML character entities will be converted.
Returns
- encode_htmlCharacter
Returns the encoded string.
Description
HTMLENCODE() transforms a string in order to make it HTML-safe. Certain characters are have special meanings within HTML documents and should not be used directly.
- & becomes &
- " becomes "e;
- ' becomes '
- < becomes <
- > becomes >
This is sufficient for most all web applications and allows you to easily store HTML and other reserved characters in your database and convert them on-the-fly for display within a web page.
Example
dim html as c =<<%html% <div style="width:50%;height:400px;"> — Northwinds Trading Co. 2017 — </div> %html% ? htmlencode(html) = <div style="width:50%;height:400px;"> — Northwinds Trading Co. 2017 — </div> ? htmlencode(html, .f.) = <div style="width:50%;height:400px;"> — Northwinds Trading Co. 2017 — </div>
Decoding HTML
To decode an encoded string, use *html_unescape():
dim encodedHtml as c = htmlencode(html) ? encodedHTML = <div style="width:50%;height:400px;"> — Northwinds Trading Co. 2017 — </div> ? *html_unescape(encodedHtml) = <div style="width:50%;height:400px;"> — Northwinds Trading Co. 2017 — </div>
See Also