Start of change

HTML_ENTITY_ENCODE

The HTML_ENTITY_ENCODE scalar function converts a string into a string with HTML entities. 

Read syntax diagramSkip visual syntax diagramHTML_ENTITY_ENCODE(string-expression )
string-expression
A string expression that returns a built-in character string. The string will be converted to a varying length character string in CCSID 1208 before encoding.

The result of the function is a varying length character string with a CCSID of 1208 in which HTML entities have been encoded.

The following rules are used for the encoding:

  • <, >, &, ", and '  are converted into &lt;, &gt;, &amp;, &quot;, and &apos;. 
  • The horizontal tabulation (HT or UX'0009'), line feed (LF or UX'000A'), and carriage return (CR or UX'000D') control characters are unchanged.
  • The remaining non-control characters that can be represented in 7-bit ASCII are unchanged.
  • All other characters are converted to HTML entities of the form &#xXXXX where XXXX is the hexadecimal value of the character.

Example

  • Encode a string containing & < > '   and "
    VALUES HTML_ENTITY_ENCODE('&<>''"') 
    Returns
    &amp;&lt;&gt;&apos;&quot; 
  • Encode a string containing UNICODE values.
    VALUES HTML_ENTITY_ENCODE(UX'0E010E230E380E130E320E420E170E230E2B0E320E090E310E19') 
    Returns
    &#xe01;&#xe23;&#xe38;&#xe13;&#xe32;&#xe42;&#xe17;&#xe23;&#xe2b;&#xe32;&#xe09;&#xe31;&#xe19;  
End of change