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.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-2

Parameters

No.TypeDescription
1
input
string input string

Original string containing special characters

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 String with encoded characters

Converted string with encoded characters

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/>

Output

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

See also

chr
decode entities