encode entities

Prev Next

Function Names

encode entities

Description

This function encodes the following special characters into character entities:

Characters Character Entity Conversion
> > (greater than)
< &lt; (less than)
" &quot; (double quotation marks)
' &#39; (apostrophe / single quotation marks)
& &amp; (ampersand symbol)
All control characters &#nnn; (e.g. new line, tab, backspace, escape)
ANSI 0 (NUL) Will be ignored
All non-ANSI characters &#nnn; (e.g. &eur; ≥ é)
Consecutive spaces &#32; (every 2nd space is converted)

See dump entities() to obtain a complete list of entities B4P is supporting.

Vectorization: This function supports vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1-2

Parameters

No.TypeDescription
1
input
string
set
input string

This string contains entities to be encoded. Vectorization can be used to provide multiple strings in a (nested) set.

Opt. 2
input
boolean use new line in html format

If false: Converts to
If true: Converts to
.

Default value: false

Return value

TypeDescription
string
set
String with encoded characters

Converted string with decoded characters. If vectorization is used, then a set containing multiple strings is returned.

Exceptions

Invalid character code (outside 0 - 1114111 range)

Examples

               echo( encode entities( '4.50 €  <TABLE> "..." </DIV>' ) );
               echo( encode entities( Line 1 + new line + Line 2, false ) ); // use &#10;
               echo( encode entities( Line 1 + new line + Line 2, true ) ); // use <BR/>
               echo( encode entities( {Café,Caffè} ) ); // Vectorization example

Output

4.50 &#8364; &#32;&lt;TABLE&gt; &quot;...&quot; &lt;/DIV&gt;
Line 1&#10;Line 2
Line 1<BR/>Line 2
{'Caf&#233;','Caff&#232;'}
Try it yourself: Open LIB_Function_encode_entities.b4p in B4P_Examples.zip. Decompress before use.

See also

chr
decode entities