rex_formatter
in package
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
Return values
stringcustom()
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
Return values
stringdate()
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
Return values
stringemail()
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
Return values
stringintlDate()
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, likeIntlDateFormatter::MEDIUM
- string pattern, likedd.MM.y
Defaults toIntlDateFormatter::MEDIUM
Tags
Return values
stringintlDateTime()
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, likeIntlDateFormatter::MEDIUM
- array with twoIntlDateFormatter
constants for date format and time format, like[IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT]
- string pattern, likedd.MM.y
Defaults to[IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT]
Tags
Return values
stringintlTime()
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, likeIntlDateFormatter::MEDIUM
- string pattern, likeHH:mm
Defaults toIntlDateFormatter::SHORT
Tags
Return values
stringnl2br()
Formats a string by `nl2br`.
public
static nl2br(string $value) : string
Parameters
- $value : string
-
Value
Tags
Return values
stringnumber()
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
Return values
stringsprintf()
Formats a string by `sprintf()`.
public
static sprintf(string $value[, string $format = '' ]) : string
Parameters
- $value : string
-
Value
- $format : string = ''
Tags
Return values
stringstrftime()
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
Return values
stringtruncate()
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
stringurl()
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
version()
Formats a version string by `sprintf()`.
public
static version(string $value, string $format) : string
Parameters
- $value : string
-
Version
- $format : string
-
Version format, e.g. "%s.%s"
Tags
Return values
stringwidont()
Avoid widows in a string.
public
static widont(string $value) : string
Parameters
- $value : string