EncodeHTML

Converts special characters to HTML entities.

Syntax

LOADLIB "wh::system.whlib";

STRING FUNCTION EncodeHTML(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. EncodeHTML returns string with these conversions made.

The function is useful to prevent user-supplied text from containing HTML markup. It will translate any character outside the printable ASCII character set, and all dangerous characters (<, >, &), into a HTML entitity.

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

Examples

// returns "&#60;HTML&#62;"
STRING example1 := EncodeHTML("<HTML>");

// returns "Johnny <br /> Jane"
STRING example2 := EncodeHTML("Johnny \n 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>');