EncodeValue (open)

Converts special characters to HTML entities.

Syntax

// Core function, no LOADLIB necessary

STRING FUNCTION EncodeValue(STRING text)

Parameters

STRING text

String to encode

Return value

STRING

The encoded string

Description

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. EncodeValue returns string with these conversions made.

The function is useful to prevent user-supplied text from accidentally closing an attribute in an HTML attribute, like "href" and "src". It will translate any character outside the printable ASCII character set, and all dangerous characters (<, >, &, ', "), into a HTML entitity.

The function resembles EncodeHTML, with the exception that it translates linebreaks into entities, as opposed to tags

Examples

// returns "<HTML>"
STRING example1 := EncodeValue ("<HTML>");

// returns "Johnny &#38; Jane"
STRING example2 := EncodeValue ("Johnny & Jane");

// returns a link with the proper encoded url and text for the file
// with ID=1.
RECORD file := FindFile(1);
PRINT('<a href="' || EncodeValue(file.url) || '">'
                  || EncodeHTML(file.title) || '</a>');