class Format

Format Library which allows a country specific formatting of numbers and dates and various other format functions

Constants

FORMAT_MARKDOWN

FORMAT_REVERSE_MARKDOWN

FORMAT_PLAINTEXT

FORMAT_MISC

Properties

static MarkdownExtra_Parser_xf $markdown_static
static Markdownify_Extra $reverse_markdown_static
static $Numbers_Words
$regex_match_links

Methods

__construct()

No description

string
_link_parse(array $matches)

Parse links

_link_parse_markdown($matches)

No description

_text_pre_parse_links($matches)

No description

string
build_telephone_number(string $number, $country = false, $alphanumeric = true)

builds a callable telephone number from given string.

string
convert_letters_to_telephone_number($number, $key_pad = 'INT_STANDARD')

converts letters in given telephone number to corresponding numbers

empty2nbsp($value)

Formats the output for a table cell - if empty a NBSP is returned

string
format_boolean($input, $options = array())

Formats a boolean value

mixed
format_by_callback(mixed $input, mixed $options = array())

No description

format_cast($input, $type)

No description

format_contrast_color($hexcolor, $dark = 'black', $light = 'white')

No description

string
format_date(bool|int $input = false, array $options = array())

Formats a date

string
format_datetime(int $input, array $options = array())

Formats a date time

format_duration($seconds, mixed $options = array())

Format Duration

format_email($input, $options = array())

No description

string
format_filesize($input, array $options = [])

Format file size

format_friendly_date($date, $dateformat = '%x %R', $options = array())

No description

string|string[]|null
format_hashtags(mixed $text_with_hashtags)

Returns a well formatted HTML of the passed tags with special formatting of the hashtags

mixed|string
format_highlight_syntax(mixed $text, string $format = 'auto')

Highlight Passed Text using a Syntax Highlighter Engine

string
format_insert(string $input, string $target)

No description

string
format_money(float $input, $options = array())

Formats a money amount

array|float|string
format_number(float $input, array $options = array())

Formats a number according to local standards and options

string
format_number_js($input)

Formats a number to be used in javascript (replace ',' with '.' and remove any spaces

string
format_percent(float $input, $options = array())

Formats a percent value

string
format_rrule(string $rrule)

Formats an rrule to a verbose label

format_sprintf(mixed $input, mixed $parameters)

No description

string
format_string($string, bool $apply_gettext = true)

No description

format_template_specialchars($text)

No description

mixed|string
format_text(string $text, string $style = Format::FORMAT_MARKDOWN, array $options = array())

Format Text String e.g. with Markdown

string
format_text_js(string $input)

Formats a text to be included in javascript

string
format_time(int $input, array $options = array())

Formats a time

string
format_timespan(array $input, array $options = array())

Formats a timespan between two dates

bool|string
format_userlink($id)

Takes a numeric input and returns an rendered XUI_USERLINK

string
get_formatted_tag_cloud(array $tag_cloud_array, array $link_params, array $options = array(), Link $xf_link = null)

Formats a get_tag_cloud() return using different font-sizes

mixed|string
highlight_search_words(string $subject, array $words, bool $alphanumeric = true)

No description

string
html_to_imgresized(string $html)

DEPRECATED - Please use >image_resize_parse

string
image_resize_parse(string $html)

Adds XF image resize params to each image in the passed HTML string e.g. will be replaced to:

image_resize_parse_cb(mixed $matches)

Callback for image_resize_parse

bool
is_utf8($str)

Checks the given string for utf-8 encoding.

string
limit_string(string $string, int $charlimit = 200)

Checks if the last character is or isnt a space. (does it the normal way if it is) It explodes the string into an array of seperate words, the effect is... it chops off anything after and including the last space.

string
link_parse(string $text)

Parst einen Text

string
money_to_str(float $money_float, string $int_curr = '')

Converts a currency value to word representation (1.02 => one dollar two cents) If the number has not any fraction part, the "cents" number is omitted.

string
multi_format(float $input, array $options)

Universal formatting function uses option array for further parameters Can be used for providing flexible formatting options within other components

array|mixed
multi_format_array(array $input_array, array $options, $type = '2dim')

No description

string
multi_format_queue(mixed $input, $format_queue)

No description

string
number_to_str(int $number)

Converts a number to its word representation

str_to_number($string)

Converts a string to the corresponding number using the local number settings

string
text_parse(string $text, bool $nl2br = true, bool $parse_hash_tags = false)

Parst einen Text

text_pre_parse($text)

Parses the passed text

wiki_parse($text)

No description

Details

at line 31
__construct()

No description

Parse links

Internal links remain unchanged. External links are modified by prepend a redirect.

Parameters

array $matches

Return Value

string

No description

Parameters

$matches

No description

Parameters

$matches

at line 1737
string build_telephone_number(string $number, $country = false, $alphanumeric = true)

builds a callable telephone number from given string.

Prefixes country code based on given $country (valid strings are in tbl|system_lib_country). Example: $number = "0172 / 123-456", $contry = "Germany" returns: $number = "+49172123456"

Parameters

string $number
$country
$alphanumeric

Return Value

string

$number

at line 1812
string convert_letters_to_telephone_number($number, $key_pad = 'INT_STANDARD')

converts letters in given telephone number to corresponding numbers

Parameters

$number
$key_pad

Return Value

string

$converted_number_without_letters

at line 585
empty2nbsp($value)

Formats the output for a table cell - if empty a NBSP is returned

Parameters

$value

at line 551
string format_boolean($input, $options = array())

Formats a boolean value

Parameters

$input
$options

Return Value

string

Formatted boolean

at line 502
mixed format_by_callback(mixed $input, mixed $options = array())

No description

Parameters

mixed $input

Input Value

mixed $options

Options

Return Value

mixed

at line 417
format_cast($input, $type)

No description

Parameters

$input
$type

at line 425
format_contrast_color($hexcolor, $dark = 'black', $light = 'white')

No description

Parameters

$hexcolor
$dark
$light

at line 712
string format_date(bool|int $input = false, array $options = array())

Formats a date

Parameters

bool|int $input

Timestamp (UTC)

array $options

Options: array('from_string'=>true, 'show_weekday'=>true, 'day_month'=>true, 'month_year'=>true, 'month'=>true, 'year'=>true, 'custom_format'=>'%B %Y (strftime syntax)' )

Return Value

string

Formatted date in local time

at line 825
string format_datetime(int $input, array $options = array())

Formats a date time

Parameters

int $input

Timestamp (UTC) or datestring if option from_string=true

array $options

Return Value

string

Formatted date/time in local time

at line 619
format_duration($seconds, mixed $options = array())

Format Duration

Parameters

$seconds
mixed $options

[weeks, days, hours, minutes, seconds]

at line 1052
format_email($input, $options = array())

No description

Parameters

$input
$options

at line 518
string format_filesize($input, array $options = [])

Format file size

Parameters

$input
array $options

Return Value

string

at line 770
format_friendly_date($date, $dateformat = '%x %R', $options = array())

No description

Parameters

$date
$dateformat
$options

at line 1465
string|string[]|null format_hashtags(mixed $text_with_hashtags)

Returns a well formatted HTML of the passed tags with special formatting of the hashtags

Parameters

mixed $text_with_hashtags

Return Value

string|string[]|null

Exceptions

Exception

at line 129
mixed|string format_highlight_syntax(mixed $text, string $format = 'auto')

Highlight Passed Text using a Syntax Highlighter Engine

Parameters

mixed $text
string $format

Syntax, e.g. php, html, xml, css, sql

Return Value

mixed|string

at line 538
string format_insert(string $input, string $target)

No description

Parameters

string $input

Input value

string $target

Haystack (e.g. 'My value goes here: %s')

Return Value

string

at line 935
string format_money(float $input, $options = array())

Formats a money amount

Parameters

float $input

Input value

$options

Return Value

string

at line 967
array|float|string format_number(float $input, array $options = array())

Formats a number according to local standards and options

Parameters

float $input

Number(s) to format (can be a float OR an 1-dim array with floats)

array $options

Assoc-Array containing the desired options [max_precision, min_precison, fixed_precision, auto_precision, colorize]

Return Value

array|float|string

at line 1106
string format_number_js($input)

Formats a number to be used in javascript (replace ',' with '.' and remove any spaces

Parameters

$input

Return Value

string

Number in JS Format e.g 1450.35

at line 599
string format_percent(float $input, $options = array())

Formats a percent value

Parameters

float $input
$options

Return Value

string

Formatted percent value

at line 1080
string format_rrule(string $rrule)

Formats an rrule to a verbose label

Parameters

string $rrule

RRule

Return Value

string

at line 439
format_sprintf(mixed $input, mixed $parameters)

No description

Parameters

mixed $input
mixed $parameters

at line 460
string format_string($string, bool $apply_gettext = true)

No description

Parameters

$string
bool $apply_gettext

Set to false if gettext should not be applied

Return Value

string

Examples

echo $XF->lib->format->format_string('["HALLO %s %s %s", {"value": "123451232", "format": "date"}, 221
, 333]');

at line 1512
format_template_specialchars($text)

No description

Parameters

$text

at line 55
mixed|string format_text(string $text, string $style = Format::FORMAT_MARKDOWN, array $options = array())

Format Text String e.g. with Markdown

Possible Options:

  • markdown:
  • allow_html (true|false)
  • entity_decoding (true - use true if converting HTML to plaintext e.g. for email or SMS | false - use false for sanitizing)

Parameters

string $text
string $style

(default (nl2br), markdown, reverse_markdown, plaintext )

array $options

['allow_html'=> false, 'allow_images' => true, 'skip_code_highlight' => false, 'entity_decoding' => true]

Return Value

mixed|string

at line 1117
string format_text_js(string $input)

Formats a text to be included in javascript

Parameters

string $input

Input

Return Value

string

Escaped Backslashes, Quotes etc.

at line 684
string format_time(int $input, array $options = array())

Formats a time

Parameters

int $input

Timestamp (UTC)

array $options

Return Value

string

Formatted time in local time

at line 892
string format_timespan(array $input, array $options = array())

Formats a timespan between two dates

Parameters

array $input

array($start_ts, $end_ts)

array $options

See format_datetime for valid options

Return Value

string

Takes a numeric input and returns an rendered XUI_USERLINK

Parameters

$id

Return Value

bool|string

at line 1257
string get_formatted_tag_cloud(array $tag_cloud_array, array $link_params, array $options = array(), Link $xf_link = null)

Formats a get_tag_cloud() return using different font-sizes

Parameters

array $tag_cloud_array

get_tag_cloud()-Return-Array

array $link_params

Link-Parameters which should be used to print Tag-Cloud-Links (print_link()-Format, Available Variables: ###tag_id### and ###tag_text###)

array $options

Font-Size Parameters: e.g. array('min_size'=>0.8, 'max_size'=>1.6) Names of selected class (get class 'selected') -> selected_tags => array('testgag');

Link $xf_link

link object for handling dependencies $this->mod->get_xf_link()

Return Value

string

at line 1659
mixed|string highlight_search_words(string $subject, array $words, bool $alphanumeric = true)

No description

Parameters

string $subject

Subject String

array $words

List of words to highlight

bool $alphanumeric

If true removes all symbols which are neither letters or numbers

Return Value

mixed|string

at line 1591
string html_to_imgresized(string $html)

DEPRECATED - Please use >image_resize_parse

Parameters

string $html

Return Value

string

$parsed_html

at line 1602
string image_resize_parse(string $html)

Adds XF image resize params to each image in the passed HTML string e.g. will be replaced to:

Parameters

string $html

HTML source

Return Value

string

HTML source

at line 1610
image_resize_parse_cb(mixed $matches)

Callback for image_resize_parse

Parameters

mixed $matches

at line 1693
bool is_utf8($str)

Checks the given string for utf-8 encoding.

Parameters

$str

Return Value

bool

is utf8

at line 221
string limit_string(string $string, int $charlimit = 200)

Checks if the last character is or isnt a space. (does it the normal way if it is) It explodes the string into an array of seperate words, the effect is... it chops off anything after and including the last space.

Parameters

string $string

Text to cut

int $charlimit

Max Chars to show

Return Value

string

Parst einen Text

Parameters

string $text

Text

Return Value

string

$text Text geparst

at line 1232
string money_to_str(float $money_float, string $int_curr = '')

Converts a currency value to word representation (1.02 => one dollar two cents) If the number has not any fraction part, the "cents" number is omitted.

Parameters

float $money_float

A float/integer/string number representing currency value

string $int_curr

International currency symbol as defined by the ISO 4217 standard (three characters). E.g. 'EUR', 'USD', 'PLN'. Optional. Defaults to $def_currency defined in the language class.

Return Value

string

The corresponding word representation [false if impossible to convert]

at line 272
string multi_format(float $input, array $options)

Universal formatting function uses option array for further parameters Can be used for providing flexible formatting options within other components

Example Format $options['format']="money"; $options['options']['decimals']=2; $options['suffix']=" EUR";

Parameters

float $input

Input

array $options

Array containing the desired options

Return Value

string

Formatted date in local time

at line 237
array|mixed multi_format_array(array $input_array, array $options, $type = '2dim')

No description

Parameters

array $input_array

Input Array

array $options

Options Array

$type

Return Value

array|mixed

at line 379
string multi_format_queue(mixed $input, $format_queue)

No description

Parameters

mixed $input

Input Value

$format_queue

Return Value

string

Returns a formatted string

at line 1207
string number_to_str(int $number)

Converts a number to its word representation

Parameters

int $number

An integer between -infinity and infinity inclusive :) that should be converted to a words representation

Return Value

string

The corresponding word representation

at line 1181
str_to_number($string)

Converts a string to the corresponding number using the local number settings

Parameters

$string

at line 1389
string text_parse(string $text, bool $nl2br = true, bool $parse_hash_tags = false)

Parst einen Text

Parameters

string $text

Newline conversion ? [Multiple Newlines]

bool $nl2br

Parse for #Tags?

bool $parse_hash_tags

Return Value

string

Exceptions

Exception

at line 1483
text_pre_parse($text)

Parses the passed text

Parameters

$text

at line 1187
wiki_parse($text)

No description

Parameters

$text