This component supports selected PHP functions in the application templates. It allows the template developer to process strings and numbers using native PHP functions such as strlen, htmlspecialchars, number_format, and stripslashes. For a complete list of the supported functions, please see below.


<fm:TextFunctions mode="number_format" decimals="2" > 1234567 </fm:TextFunctions>

The above will display the integer 1234567 formatted into 1,000's, with 2 significant digits shown after the decimal. The result: 1,234,567.00

NOTE: The 'mode' is required.

Supported attributes

escapeOptionalThis will convert special characters to HTML entities: i.e. converting <a> to
html_entity_decodeOptionalThis will convert all HTML entities to their applicable characters
htmlentitiesOptionalThis will convert all applicable characters to HTML entities
htmlspecialcharsOptionalThis will convert special characters to HTML entities
htmlspecialchars_decodeOptionalThis will convert HTML entities back to special characters: i.e. converting <a> to &lt;a&gt;
jsonencodeOptionalCreates json safe text, also supports 'dontquote' parameter that will return json safe string without surrounding quotes
modeOptionalsanitizeWhether to sanitize or escape the content. Valid values are "sanitize" and "escape".
money_formatOptionalThis will format a number as a currency string, with 2 decimal places: i.e: $10
nl2brOptionalInserts HTML line breaks before all newlines in a string. (This will convert all newlines to html <br/> )
number_formatOptionalThis will format a number with grouped thousands: i.e. 1,234,567
There is an optional second parameter for this function: it is decimals (integer). Passing 'decimals' sets the number of decimal places to be shown after the decimal point. So if decimals="2" is passed in the example above, then the result would be: 1,234,567.00
Default: If the value for decimals is not passed, then the default is 0
removelinebreaksOptionalThis will make remove any line breaks in a string
rtrimOptionalThis will strip whitespace (or other characters) from the end of a string
sanitizeOptionalThis will strip HTML and PHP tags from a string
stringreplaceOptionalReplace's parameter 'find' with parameter 'replace' in the provided text, can also accept regex 'modifier' param
strip_tagsOptionalThis will strip HTML and PHP tags from a string
stripcslashesOptionalThis will un-quote a string quoted with addcslashes - it will take off 1 slash from a series of slashes (if there are 2 slashes, then 1 will remain)
stripslashesOptionalThis will un-quote a quoted string - it will take off 2 slashes from a series of slashes (if there are 3 slashes, then 1 will remain)
strlenOptionalThis will get the length of a string, including whitespace at the beginning and end of the string
strrevOptionalThis will reverse a string
strtolowerOptionalThis will make a string lowercase
strtoupperOptionalThis will make a string uppercase
tabs2spaceOptionalReplaces all tab characters with spaces
tidyxmlOptionalThis will clean up XML content, replacing invalid characters when needed
trimOptionalWill remove all whitespace when set to anything but empty. This defaults to being off.
ucfirstOptionalThis will make the first character of a string uppercase. NB: If the first character of the string is an empty space, there wil be no visible capitalization.
ucwordsOptionalThis will make the first character of each word in a string uppercase

Optional notes about the supported attributes.

Template variables

This component defines no template variables.

This component does not output variables, just plain html or text.

See also

More examples

Example 1: escape:

'escape' converts HTML to escaped characters: i.e. converting <a> to &lt;a&gt;
The following code will convert <p> to &lt;p&gt; (view 'source code')

<fm:TextFunctions mode="escape" > <p> </fm:TextFunctions>

Example 2: strlen:

'strlen' displays the length of a string
The following code will display: 16

<fm:TextFunctions mode="strlen" >this is a string</fm:TextFunctions>

Example 3: stripslashes:

'stripslashes' will un-quote a string quoted with addcslashes
The following code will display: this is a string with its slash deleted

<fm:TextFunctions mode="stripslashes" >this is a string with its\ slash deleted</fm:TextFunctions>