class Str

Collection of string manipulation methods.

Constants

ALNUM

Alphanumeric characters.

ALPHA

Alphabetic characters.

HEXDEC

Hexadecimal characters.

NUMERIC

Numeric characters.

SYMBOLS

ASCII symbols.

Properties

static protected array $pluralizationRules Pluralization rules.
static protected array $irregulars Irregular nouns.

Methods

static string
nl2br(string $string, bool $xhtml = false)

Replaces newline with
or
.

static string
br2nl(string $string)

Replaces
and
with newline.

static string
pluralize(string $noun, int|null $count = null)

Returns the plural form of a noun (english only).

static string
camel2underscored(string $string)

Converts camel case to underscored.

static string
underscored2camel(string $string, bool $upper = false)

Converts underscored to camel case.

static string
limitChars(string $string, int $characters = 100, string $sufix = '...')

Limits the number of characters in a string.

static string
limitWords(string $string, int $words = 100, string $sufix = '...')

Limits the number of words in a string.

static string
slug(string $string)

Creates a URL friendly string.

static string
ascii(string $string)

Strips all non-ASCII characters.

static Closure
alternator(array $strings)

Returns a closure that will alternate between the defined strings.

static string
autolink(string $string, array $attributes = [])

Converts URLs in a text into clickable links.

static string
mask(string $string, int $visible = 3, string $mask = '*')

Returns a masked string where only the last n characters are visible.

static string
increment(string $string, int $start = 1, string $separator = '_')

Increments a string by appending a number to it or increasing the number.

static string
random(string $pool = Str::ALNUM, int $length = 32)

Returns a random string of the selected type and length.

Details

at line 135
static string nl2br(string $string, bool $xhtml = false)

Replaces newline with
or
.

Parameters

string $string The input string
bool $xhtml Should we return XHTML?

Return Value

string

at line 146
static string br2nl(string $string)

Replaces
and
with newline.

Parameters

string $string The input string

Return Value

string

at line 158
static string pluralize(string $noun, int|null $count = null)

Returns the plural form of a noun (english only).

Parameters

string $noun Noun to pluralize
int|null $count Number of nouns

Return Value

string

at line 189
static string camel2underscored(string $string)

Converts camel case to underscored.

Parameters

string $string The input string

Return Value

string

at line 201
static string underscored2camel(string $string, bool $upper = false)

Converts underscored to camel case.

Parameters

string $string The input string
bool $upper Return upper case camelCase?

Return Value

string

at line 214
static string limitChars(string $string, int $characters = 100, string $sufix = '...')

Limits the number of characters in a string.

Parameters

string $string The input string
int $characters Number of characters to allow
string $sufix Sufix to add if number of characters is reduced

Return Value

string

at line 227
static string limitWords(string $string, int $words = 100, string $sufix = '...')

Limits the number of words in a string.

Parameters

string $string The input string
int $words Number of words to allow
string $sufix Sufix to add if number of words is reduced

Return Value

string

at line 245
static string slug(string $string)

Creates a URL friendly string.

Parameters

string $string The input string

Return Value

string

at line 256
static string ascii(string $string)

Strips all non-ASCII characters.

Parameters

string $string The input string

Return Value

string

at line 267
static Closure alternator(array $strings)

Returns a closure that will alternate between the defined strings.

Parameters

array $strings Array of strings to alternate between

Return Value

Closure

Converts URLs in a text into clickable links.

Parameters

string $string Text to scan for links
array $attributes Anchor attributes

Return Value

string

at line 300
static string mask(string $string, int $visible = 3, string $mask = '*')

Returns a masked string where only the last n characters are visible.

Parameters

string $string String to mask
int $visible Number of characters to show
string $mask Character used to replace remaining characters

Return Value

string

at line 320
static string increment(string $string, int $start = 1, string $separator = '_')

Increments a string by appending a number to it or increasing the number.

Parameters

string $string String to increment
int $start Starting number
string $separator Separator

Return Value

string

at line 334
static string random(string $pool = Str::ALNUM, int $length = 32)

Returns a random string of the selected type and length.

Parameters

string $pool Character pool to use
int $length Desired string length

Return Value

string