Documentation

rex_formatter
in package

AbstractYes

String formatter class.

Table of Contents

Methods

bytes()  : string
Formats a string as bytes.
custom()  : string
Formats a string by a custom callable.
date()  : string
Formats a string by `date()`.
email()  : string
Formats a string as email link.
format()  : string
Formats a string by the given format type.
intlDate()  : string
Formats a date by `IntlDateFormmater`.
intlDateTime()  : string
Formats a datetime by `IntlDateFormmater`.
intlTime()  : string
Formats a time by `IntlDateFormmater`.
nl2br()  : string
Formats a string by `nl2br`.
number()  : string
Formats a string by `number_format()`.
sprintf()  : string
Formats a string by `sprintf()`.
strftime()  : string
Formats a string by `strftime()`.
truncate()  : string
Truncates a string.
url()  : string
Formats a string as link.
version()  : string
Formats a version string by `sprintf()`.
widont()  : string
Avoid widows in a string.

Methods

bytes()

Formats a string as bytes.

public static bytes(string|int $value[, array<string|int, mixed> $format = [] ]) : string
Parameters
$value : string|int

Value

$format : array<string|int, mixed> = []

Same as

Return values
string

custom()

Formats a string by a custom callable.

public static custom(string $value, callable|array<string|int, mixed> $format) : string
Parameters
$value : string

Value

$format : callable|array<string|int, mixed>

A callable or an array of a callable and additional params

Tags
psalm-param

callable(string):string|array{0: callable(non-empty-array):string, 1: mixed} $format

throws
rex_exception
Return values
string

date()

Formats a string by `date()`.

public static date(string|int|null $value[, string $format = '' ]) : string
Parameters
$value : string|int|null

Unix timestamp or datetime string for strtotime

$format : string = ''

Default format is d.m.Y

Tags
see
https://www.php.net/manual/en/function.date.php
Return values
string

email()

Formats a string as email link.

public static email(string $value[, array<string|int, mixed> $format = [] ]) : string
Parameters
$value : string

Email

$format : array<string|int, mixed> = []

Array with link attributes and params

Return values
string

Email link

format()

Formats a string by the given format type.

public static format(string $value, string $formatType, mixed $format) : string
Parameters
$value : string

Value

$formatType : string

Format type (any method name of this class)

$format : mixed

For possible values look at the other methods of this class

Tags
throws
InvalidArgumentException
Return values
string

intlDate()

Formats a date by `IntlDateFormmater`.

public static intlDate(string|int|DateTimeInterface|null $value[, IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|string|null $format = null ]) : string
Parameters
$value : string|int|DateTimeInterface|null

Unix timestamp, date string for strtotime or DateTimeInterface object

$format : IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|string|null = null

Possible format values: - IntlDateFormatter constant, like IntlDateFormatter::MEDIUM - string pattern, like dd.MM.y Defaults to IntlDateFormatter::MEDIUM

Tags
see
https://www.php.net/manual/en/class.intldateformatter.php
Return values
string

intlDateTime()

Formats a datetime by `IntlDateFormmater`.

public static intlDateTime(string|int|DateTimeInterface|null $value[, IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|IntlDateFormatter::NONE}|string|null $format = null ]) : string
Parameters
$value : string|int|DateTimeInterface|null

Unix timestamp, datetime string for strtotime or DateTimeInterface object

$format : IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|IntlDateFormatter::NONE}|string|null = null

Possible format values: - IntlDateFormatter constant, like IntlDateFormatter::MEDIUM - array with two IntlDateFormatter constants for date format and time format, like [IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT] - string pattern, like dd.MM.y Defaults to [IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT]

Tags
see
https://www.php.net/manual/en/class.intldateformatter.php
Return values
string

intlTime()

Formats a time by `IntlDateFormmater`.

public static intlTime(string|int|DateTimeInterface|null $value[, IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|string|null $format = IntlDateFormatter::SHORT ]) : string
Parameters
$value : string|int|DateTimeInterface|null

Unix timestamp, time string for strtotime or DateTimeInterface object

$format : IntlDateFormatter::FULL|IntlDateFormatter::LONG|IntlDateFormatter::MEDIUM|IntlDateFormatter::SHORT|string|null = IntlDateFormatter::SHORT

Possible format values: - IntlDateFormatter constant, like IntlDateFormatter::MEDIUM - string pattern, like HH:mm Defaults to IntlDateFormatter::SHORT

Tags
see
https://www.php.net/manual/en/class.intldateformatter.php
Return values
string

number()

Formats a string by `number_format()`.

public static number(string|float $value[, array<string|int, mixed> $format = [] ]) : string
Parameters
$value : string|float

Value

$format : array<string|int, mixed> = []

Array with number of decimals, decimals point and thousands separator, default is array(2, ',', ' ')

Tags
see
https://www.php.net/manual/en/function.number-format.php
Return values
string

strftime()

Formats a string by `strftime()`.

public static strftime(string|int|null $value[, string $format = '' ]) : string
Parameters
$value : string|int|null

Unix timestamp or datetime string for strtotime

$format : string = ''

Possible values are format strings like in strftime or "date" or "datetime", default is "date"

Tags
see
https://www.php.net/manual/en/function.strftime.php
deprecated

since 5.13.0

Return values
string

truncate()

Truncates a string.

public static truncate(string $value[, array{length?: int, etc?: string, break_words?: bool} $format = [] ]) : string
Parameters
$value : string

Value

$format : array{length?: int, etc?: string, break_words?: bool} = []

Default format is ['length' => 80, 'etc' => '…', 'break_words' => false]

Return values
string

url()

Formats a string as link.

public static url(string $value[, array<string|int, mixed> $format = [] ]) : string
Parameters
$value : string

URL

$format : array<string|int, mixed> = []

Array with link attributes and params

Return values
string

Link

widont()

Avoid widows in a string.

public static widont(string $value) : string
Parameters
$value : string
Return values
string

        
On this page

Search results