final class Filters

internal  
 

Template filters. Uses UTF-8 only.

Properties

$locale

Methods

static string
stripHtml(FilterInfo $info, string|Stringable|null $s)

Converts HTML to plain text.

static string
stripTags(FilterInfo $info, string|Stringable|null $s)

Removes tags from HTML (but remains HTML entities).

static string
strip(FilterInfo $info, string $s)

Replaces all repeated white spaces with a single space.

static string
spacelessHtml(string $s, bool $strip = true)

Replaces all repeated white spaces with a single space.

static string
spacelessHtmlHandler(string $s, int|null $phase = null)

Output buffering handler for spacelessHtml.

static string
spacelessText(string $s)

Replaces all repeated white spaces with a single space.

static string
indent(FilterInfo $info, string $s, int $level = 1, string $chars = "\t")

Indents plain text or HTML the content from the left.

static string
implode(array $arr, string $glue = '')

Join array of text or HTML elements with a string.

static string
commas(array $arr, string|null $lastGlue = null)

Join array elements with a comma and space.

static array
explode(string $value, string $separator = '')

Splits a string by a string.

static string
repeat(FilterInfo $info, string|Stringable|null $s, int $count)

Repeats text.

static string|null
date(string|int|DateTimeInterface|DateInterval|null $time, string $format = "j. n. Y")

Date/time formatting.

string|null
localDate(string|int|DateTimeInterface|null $value, string|null $format = null, string|null $date = null, string|null $time = null)

Date/time formatting according to locale.

string
number(float $number, string|int $patternOrDecimals = 0, string $decimalSeparator = '.', string $thousandsSeparator = ',')

Formats a number with grouped thousands and optionally decimal digits according to locale.

string
bytes(float $bytes, int $precision = 2)

Converts to human-readable file size.

static string
replace(FilterInfo $info, string $subject, string|array $search, string|array|null $replace = null)

Performs a search and replace.

static string
replaceRe(string $subject, string $pattern, string $replacement = '')

Perform a regular expression search and replace.

static string
dataStream(string $data, string|null $type = null)

The data: URI generator.

static Html
breaklines(string|Stringable|null $s)

Converts newlines to HTML
tags.

static string
substring(string|Stringable|null $s, int $start, int|null $length = null)

Returns a part of string.

static string
truncate(string|Stringable|null $s, int $length, string $append = "…")

Truncates string to maximal length.

static string
lower(string|Stringable|null $s)

Convert to lower case.

static string
upper(string|Stringable|null $s)

Convert to upper case.

static string
firstLower(string|Stringable|null $s)

Convert first character to lower case.

static string
firstUpper(string|Stringable|null $s)

Convert first character to upper case.

static string
capitalize(string|Stringable|null $s)

Capitalize string.

static int
length(array|Countable|Traversable|string $val)

Returns length of string or iterable.

static string
trim(FilterInfo $info, string $s, string $charlist = " \t\n\r\x00\v ")

Strips whitespace.

static string
padLeft(string|Stringable|int|float|null $s, int $length, string $append = ' ')

Pad a string to a certain length with another string.

static string
padRight(string|Stringable|int|float|null $s, int $length, string $append = ' ')

Pad a string to a certain length with another string.

static string|array
reverse(string|iterable $val, bool $preserveKeys = false)

Reverses string or array.

static array
column(iterable $data, string|int|null $columnKey, string|int|null $indexKey = null)

Returns the values from a single column in the input array.

static Generator
batch(iterable $list, int $length, mixed $rest = null)

Chunks items by returning an array of arrays with the given number of items.

iterable
sort(iterable $data, Closure|null $comparison = null, string|int|Closure|null $by = null, string|int|Closure|bool $byKey = false)

Sorts elements using the comparison function and preserves the key association.

static iterable
group(iterable $data, string|int|Closure $by)

Groups elements by the element indices and preserves the key association and order.

static iterable
filter(iterable $iterable, callable $predicate)

Filters elements according to a given $predicate. Maintains original keys.

static int|float
clamp(int|float $value, int|float $min, int|float $max)

Returns value clamped to the inclusive range of min and max.

static string
query(string|array $data)

Generates URL-encoded query string

static bool
divisibleBy(int $value, int $by)

Is divisible by?

static bool
odd(int $value)

Is odd?

static bool
even(int $value)

Is even?

static mixed
first(string|iterable $value)

Returns the first element in an array or character in a string, or null if none.

static mixed
last(string|array $value)

Returns the last element in an array or character in a string, or null if none.

static string|array|Generator
slice(string|iterable $value, int $start, int|null $length = null, bool $preserveKeys = false)

Extracts a slice of an array, string or iterator.

static float
round(float $value, int $precision = 0)

Rounds number to specified precision.

static float
floor(float $value, int $precision = 0)

Rounds number down to specified precision.

static float
ceil(float $value, int $precision = 0)

Rounds number up to specified precision.

static mixed
random(string|array $values)

Picks random element/char.

static string
checkUrl(mixed $s)

Sanitizes string for use inside href attribute.

Details

at line 31
static string stripHtml(FilterInfo $info, string|Stringable|null $s)

Converts HTML to plain text.

Parameters

FilterInfo $info
string|Stringable|null $s

Return Value

string

at line 42
static string stripTags(FilterInfo $info, string|Stringable|null $s)

Removes tags from HTML (but remains HTML entities).

Parameters

FilterInfo $info
string|Stringable|null $s

Return Value

string

at line 53
static string strip(FilterInfo $info, string $s)

Replaces all repeated white spaces with a single space.

Parameters

FilterInfo $info
string $s

Return Value

string

at line 64
static string spacelessHtml(string $s, bool $strip = true)

Replaces all repeated white spaces with a single space.

Parameters

string $s
bool $strip

Return Value

string

at line 84
static string spacelessHtmlHandler(string $s, int|null $phase = null)

Output buffering handler for spacelessHtml.

Parameters

string $s
int|null $phase

Return Value

string

at line 109
static string spacelessText(string $s)

Replaces all repeated white spaces with a single space.

Parameters

string $s

Return Value

string

at line 118
static string indent(FilterInfo $info, string $s, int $level = 1, string $chars = "\t")

Indents plain text or HTML the content from the left.

Parameters

FilterInfo $info
string $s
int $level
string $chars

Return Value

string

at line 142
static string implode(array $arr, string $glue = '')

Join array of text or HTML elements with a string.

Parameters

array $arr
string $glue

Return Value

string

at line 152
static string commas(array $arr, string|null $lastGlue = null)

Join array elements with a comma and space.

Parameters

array $arr
string|null $lastGlue

Return Value

string

at line 167
static array explode(string $value, string $separator = '')

Splits a string by a string.

Parameters

string $value
string $separator

Return Value

array

at line 178
static string repeat(FilterInfo $info, string|Stringable|null $s, int $count)

Repeats text.

Parameters

FilterInfo $info
string|Stringable|null $s
int $count

Return Value

string

at line 187
static string|null date(string|int|DateTimeInterface|DateInterval|null $time, string $format = "j. n. Y")

Date/time formatting.

Parameters

string|int|DateTimeInterface|DateInterval|null $time
string $format

Return Value

string|null

at line 209
string|null localDate(string|int|DateTimeInterface|null $value, string|null $format = null, string|null $date = null, string|null $time = null)

Date/time formatting according to locale.

Parameters

string|int|DateTimeInterface|null $value
string|null $format
string|null $date
string|null $time

Return Value

string|null

at line 249
string number(float $number, string|int $patternOrDecimals = 0, string $decimalSeparator = '.', string $thousandsSeparator = ',')

Formats a number with grouped thousands and optionally decimal digits according to locale.

Parameters

float $number
string|int $patternOrDecimals
string $decimalSeparator
string $thousandsSeparator

Return Value

string

at line 278
string bytes(float $bytes, int $precision = 2)

Converts to human-readable file size.

Parameters

float $bytes
int $precision

Return Value

string

at line 307
static string replace(FilterInfo $info, string $subject, string|array $search, string|array|null $replace = null)

Performs a search and replace.

Parameters

FilterInfo $info
string $subject
string|array $search
string|array|null $replace

Return Value

string

at line 331
static string replaceRe(string $subject, string $pattern, string $replacement = '')

Perform a regular expression search and replace.

Parameters

string $subject
string $pattern
string $replacement

Return Value

string

at line 345
static string dataStream(string $data, string|null $type = null)

The data: URI generator.

Parameters

string $data
string|null $type

Return Value

string

at line 360
static Html breaklines(string|Stringable|null $s)

Converts newlines to HTML
tags.

Parameters

string|Stringable|null $s

Return Value

Html

at line 370
static string substring(string|Stringable|null $s, int $start, int|null $length = null)

Returns a part of string.

Parameters

string|Stringable|null $s
int $start
int|null $length

Return Value

string

at line 384
static string truncate(string|Stringable|null $s, int $length, string $append = "…")

Truncates string to maximal length.

Parameters

string|Stringable|null $s
int $length
string $append

Return Value

string

at line 407
static string lower(string|Stringable|null $s)

Convert to lower case.

Parameters

string|Stringable|null $s

Return Value

string

at line 416
static string upper(string|Stringable|null $s)

Convert to upper case.

Parameters

string|Stringable|null $s

Return Value

string

at line 425
static string firstLower(string|Stringable|null $s)

Convert first character to lower case.

Parameters

string|Stringable|null $s

Return Value

string

at line 435
static string firstUpper(string|Stringable|null $s)

Convert first character to upper case.

Parameters

string|Stringable|null $s

Return Value

string

at line 445
static string capitalize(string|Stringable|null $s)

Capitalize string.

Parameters

string|Stringable|null $s

Return Value

string

at line 455
static int length(array|Countable|Traversable|string $val)

Returns length of string or iterable.

Parameters

array|Countable|Traversable|string $val

Return Value

int

at line 480
static string trim(FilterInfo $info, string $s, string $charlist = " \t\n\r\x00\v ")

Strips whitespace.

Parameters

FilterInfo $info
string $s
string $charlist

Return Value

string

at line 495
static string padLeft(string|Stringable|int|float|null $s, int $length, string $append = ' ')

Pad a string to a certain length with another string.

Parameters

string|Stringable|int|float|null $s
int $length
string $append

Return Value

string

at line 507
static string padRight(string|Stringable|int|float|null $s, int $length, string $append = ' ')

Pad a string to a certain length with another string.

Parameters

string|Stringable|int|float|null $s
int $length
string $append

Return Value

string

at line 523
static string|array reverse(string|iterable $val, bool $preserveKeys = false)

Reverses string or array.

Parameters

string|iterable $val
bool $preserveKeys

Return Value

string|array

at line 536
static array column(iterable $data, string|int|null $columnKey, string|int|null $indexKey = null)

Returns the values from a single column in the input array.

Parameters

iterable $data
string|int|null $columnKey
string|int|null $indexKey

Return Value

array

at line 547
static Generator batch(iterable $list, int $length, mixed $rest = null)

Chunks items by returning an array of arrays with the given number of items.

Parameters

iterable $list
int $length
mixed $rest

Return Value

Generator

at line 580
iterable sort(iterable $data, Closure|null $comparison = null, string|int|Closure|null $by = null, string|int|Closure|bool $byKey = false)

Sorts elements using the comparison function and preserves the key association.

Parameters

iterable $data
Closure|null $comparison
string|int|Closure|null $by
string|int|Closure|bool $byKey

Return Value

iterable

at line 633
static iterable group(iterable $data, string|int|Closure $by)

Groups elements by the element indices and preserves the key association and order.

Parameters

iterable $data
string|int|Closure $by

Return Value

iterable

at line 667
static iterable filter(iterable $iterable, callable $predicate)

Filters elements according to a given $predicate. Maintains original keys.

Parameters

iterable $iterable
callable $predicate

Return Value

iterable

at line 680
static int|float clamp(int|float $value, int|float $min, int|float $max)

Returns value clamped to the inclusive range of min and max.

Parameters

int|float $value
int|float $min
int|float $max

Return Value

int|float

at line 694
static string query(string|array $data)

Generates URL-encoded query string

Parameters

string|array $data

Return Value

string

at line 705
static bool divisibleBy(int $value, int $by)

Is divisible by?

Parameters

int $value
int $by

Return Value

bool

at line 714
static bool odd(int $value)

Is odd?

Parameters

int $value

Return Value

bool

at line 723
static bool even(int $value)

Is even?

Parameters

int $value

Return Value

bool

at line 734
static mixed first(string|iterable $value)

Returns the first element in an array or character in a string, or null if none.

Parameters

string|iterable $value

Return Value

mixed

at line 753
static mixed last(string|array $value)

Returns the last element in an array or character in a string, or null if none.

Parameters

string|array $value

Return Value

mixed

at line 766
static string|array|Generator slice(string|iterable $value, int $start, int|null $length = null, bool $preserveKeys = false)

Extracts a slice of an array, string or iterator.

Parameters

string|iterable $value
int $start
int|null $length
bool $preserveKeys

Return Value

string|array|Generator

at line 803
static float round(float $value, int $precision = 0)

Rounds number to specified precision.

Parameters

float $value
int $precision

Return Value

float

at line 812
static float floor(float $value, int $precision = 0)

Rounds number down to specified precision.

Parameters

float $value
int $precision

Return Value

float

at line 821
static float ceil(float $value, int $precision = 0)

Rounds number up to specified precision.

Parameters

float $value
int $precision

Return Value

float

at line 832
static mixed random(string|array $values)

Picks random element/char.

Parameters

string|array $values

Return Value

mixed

at line 847
static string checkUrl(mixed $s)

Sanitizes string for use inside href attribute.

Parameters

mixed $s

Return Value

string