class Str

Traits

Constants

INVISIBLE_CHARACTERS

The list of characters that are considered "invisible" in strings.

Properties

static protected array $macros

The registered string macros.

from  Macroable
static protected null|Closure(): string|Uuid $uuidFactory

The callback that should be used to generate UUIDs.

static protected null|Ulid $ulidFactory

The callback that should be used to generate ULIDs.

static protected null|Closure(int): string $randomStringFactory

The callback that should be used to generate random strings.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

static Stringable
of(mixed $string)

Get a new stringable object from the given string.

static Stringable
trans(string $key, array $replace = [], string|null $locale = null)

Translate the given message and get a new stringable object.

static string
after(string $subject, string|int|float|bool|Stringable|null $search)

Return the remainder of a string after the first occurrence of a given value.

static string
afterLast(string $subject, string|int|float|bool|Stringable|null $search)

Return the remainder of a string after the last occurrence of a given value.

static string
ascii(string|int|float|bool|Stringable|null $value, string $language = 'en')

Transliterate a UTF-8 value to ASCII.

static string
transliterate(string|int|float|bool|Stringable|null $string, string|null $unknown = '?', bool $strict = false)

Transliterate a string to its closest ASCII representation.

static string
before(string $subject, string|int|float|bool|Stringable|null $search)

Get the portion of a string before the first occurrence of a given value.

static string
beforeLast(string $subject, string|int|float|bool|Stringable|null $search)

Get the portion of a string before the last occurrence of a given value.

static string
between(string $subject, string|int|float|bool|Stringable|null $from, string|int|float|bool|Stringable|null $to)

Get the portion of a string between two given values.

static string
betweenFirst(string $subject, string|int|float|bool|Stringable|null $from, string|int|float|bool|Stringable|null $to)

Get the smallest possible portion of a string between two given values.

static string
camel(string $value)

Convert a value to camel case.

static string|false
charAt(string $subject, int $index)

Get the character at the specified index.

static string
chopStart(string $subject, string|array $needle)

Remove the given string(s) if it exists at the start of the haystack.

static string
chopEnd(string $subject, string|array $needle)

Remove the given string(s) if it exists at the end of the haystack.

static bool
contains(string $haystack, string|iterable $needles, bool $ignoreCase = false)

Determine if a given string contains a given substring.

static bool
containsAll(string $haystack, iterable $needles, bool $ignoreCase = false)

Determine if a given string contains all array values.

static bool
doesntContain(string $haystack, string|iterable $needles, bool $ignoreCase = false)

Determine if a given string doesn't contain a given substring.

static string
convertCase(string $string, int $mode = MB_CASE_FOLD, string|null $encoding = 'UTF-8')

Convert the case of a string.

static string
counted(string $value, int|array|Countable $count)

Get the plural form of an English word with the count prepended.

static string
deduplicate(string $string, array|string $characters = ' ')

Replace consecutive instances of a given character with a single character in the given string.

static bool
endsWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string ends with a given substring.

static bool
doesntEndWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string doesn't end with a given substring.

static string|null
excerpt(string|int|float|bool|Stringable|null $text, string|int|float|bool|Stringable|null $phrase = '', array $options = [])

Extract an excerpt from text that matches the first instance of a phrase.

static string
finish(string $value, string $cap)

Cap a string with a single instance of a given value.

static string
wrap(string $value, string $before, string|null $after = null)

Wrap the string with the given strings.

static string
unwrap(string $value, string $before, string|null $after = null)

Unwrap the string with the given strings.

static bool
is(string|int|float|bool|Stringable|iterable|null $pattern, string|int|float|bool|Stringable|null $value, bool $ignoreCase = false)

Determine if a given string matches a given pattern.

static bool
isAscii(string|int|float|bool|Stringable|null $value)

Determine if a given string is 7 bit ASCII.

static bool
isJson(mixed $value)

Determine if a given value is valid JSON.

static bool
isUrl(mixed $value, array $protocols = [])

Determine if a given value is a valid URL.

static bool
isUuid(mixed $value, int|string|null $version = null)

Determine if a given value is a valid UUID.

static bool
isUlid(mixed $value)

Determine if a given value is a valid ULID.

static string
kebab(string $value)

Convert a string to kebab case.

static int
length(string $value, string|null $encoding = null)

Return the length of the given string.

static string
limit(string $value, int $limit = 100, string $end = '...', bool $preserveWords = false)

Limit the number of characters in a string.

static string
lower(string $value)

Convert the given string to lower-case.

static string
words(string $value, int $words = 100, string $end = '...')

Limit the number of words in a string.

static string
markdown(string|int|float|bool|Stringable|null $string, array $options = [], array $extensions = [])

Convert GitHub flavored Markdown into HTML.

static string
inlineMarkdown(string|int|float|bool|Stringable|null $string, array $options = [], array $extensions = [])

Convert inline Markdown into HTML.

static string
mask(string $string, string|Stringable $character, int $index, int|null $length = null, string $encoding = 'UTF-8')

Mask a portion of a string with a repeated character.

static string
match(string $pattern, string $subject)

Get the string matching the given pattern.

static bool
isMatch(string|iterable $pattern, string $value)

Determine if a given string matches a given pattern.

static Collection
matchAll(string $pattern, string $subject)

Get the string matching the given pattern.

static string|array
numbers(string|array $value)

Remove all non-numeric characters from a string.

static string
padBoth(string $value, int $length, string $pad = ' ')

Pad both sides of a string with another.

static string
padLeft(string $value, int $length, string $pad = ' ')

Pad the left side of a string with another.

static string
padRight(string $value, int $length, string $pad = ' ')

Pad the right side of a string with another.

static array
parseCallback(string $callback, string|null $default = null)

Parse a Class[@]method style callback into class and method.

static string
plural(string $value, int|array|Countable $count = 2, bool $prependCount = false)

Get the plural form of an English word.

static string
pluralStudly(string $value, int|array|Countable $count = 2)

Pluralize the last word of an English, studly caps case string.

static string
pluralPascal(string $value, int|array|Countable $count = 2)

Pluralize the last word of an English, Pascal caps case string.

static string
password(int $length = 32, bool $letters = true, bool $numbers = true, bool $symbols = true, bool $spaces = false)

Generate a random, secure password.

static int|false
position(string $haystack, string $needle, int $offset = 0, string|null $encoding = null)

Find the multi-byte safe position of the first occurrence of a given substring in a string.

static string
random(int $length = 16)

Generate a more truly "random" alpha-numeric string.

static void
createRandomStringsUsing(callable|null $factory = null)

Set the callable that will be used to generate random strings.

static void
createRandomStringsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate random strings.

static void
createRandomStringsNormally()

Indicate that random strings should be created normally and not using a custom factory.

static string
repeat(string $string, int $times)

Repeat the given string.

static string
replaceArray(string $search, iterable $replace, string $subject)

Replace a given value in the string sequentially with an array.

static string|array
replace(string|iterable $search, string|iterable $replace, string|iterable $subject, bool $caseSensitive = true)

Replace the given value in the given string.

static string|array
replaceWhileIgnoringCase(string|array $search, string|array $replace, string|array $subject)

Replace the given value in the given string regardless of case.

static string
replaceFirst(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the first occurrence of a given value in the string.

static string
replaceStart(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the first occurrence of the given value if it appears at the start of the string.

static string
replaceLast(string $search, string $replace, string $subject)

Replace the last occurrence of a given value in the string.

static string
replaceEnd(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the last occurrence of a given value if it appears at the end of the string.

static string|array|null
replaceMatches(string|array $pattern, Closure|array|string $replace, string|array $subject, int $limit = -1)

Replace the patterns matching the given regular expression.

static string
remove(string|iterable $search, string $subject, bool $caseSensitive = true)

Remove any occurrence of the given string in the subject.

static string
reverse(string $value)

Reverse the given string.

static string
start(string $value, string $prefix)

Begin a string with a single instance of a given value.

static string
upper(string $value)

Convert the given string to upper-case.

static string
title(string $value)

Convert the given string to proper case.

static string
headline(string $value)

Convert the given string to proper case for each word.

static string
initials(string $value, bool $capitalize = false)

Get the "initials" representing each word in the provided string, optionally capitalizing.

static string
apa(string $value)

Convert the given string to APA-style title case.

static string
singular(string $value)

Get the singular form of an English word.

static string
slug(string|int|float|bool|Stringable|null $title, string $separator = '-', string|null $language = 'en', array $dictionary = ['@' => 'at'])

Generate a URL friendly "slug" from a given string.

static string
snake(string $value, string $delimiter = '_')

Convert a string to snake case.

static string
trim(string $value, string|null $charlist = null)

Remove all whitespace from both ends of a string.

static string
ltrim(string $value, string|null $charlist = null)

Remove all whitespace from the beginning of a string.

static string
rtrim(string $value, string|null $charlist = null)

Remove all whitespace from the end of a string.

static string
squish(string $value)

Remove all "extra" blank space from the given string.

static bool
startsWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string starts with a given substring.

static bool
doesntStartWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string doesn't start with a given substring.

static string
studly(string $value, bool $normalize = false)

Convert a value to studly caps case.

static string
pascal(string $value, bool $normalize = false)

Convert a value to Pascal case.

static string
substr(string $string, int $start, int|null $length = null, string $encoding = 'UTF-8')

Return the portion of the string specified by the start and length parameters.

static int
substrCount(string $haystack, string $needle, int $offset = 0, int|null $length = null)

Return the number of substring occurrences.

static string|array
substrReplace(string|array $string, string|array $replace, int|array $offset = 0, int|array|null $length = null)

Replace text within a portion of a string.

static string
swap(array $map, string $subject)

Swap multiple keywords in a string with other keywords.

static string
take(string $string, int $limit)

Take the first or last {$limit} characters of a string.

static string
toBase64(string $string)

Convert the given string to Base64 encoding.

static string|false
fromBase64(string $string, bool $strict = false)

Decode the given Base64 encoded string.

static string
lcfirst(string $string)

Make a string's first character lowercase.

static string
ucfirst(string $string)

Make a string's first character uppercase.

static string
ucwords(string $string, string $separators = " \t\r\n\f\v")

Capitalize the first character of each word in a string.

static array
ucsplit(string $string)

Split a string into pieces by uppercase characters.

static int
wordCount(string $string, string|null $characters = null)

Get the number of words a string contains.

static string
wordWrap(string $string, int $characters = 75, string $break = "\n", bool $cutLongWords = false)

Wrap a string to a given number of characters.

static Uuid
uuid()

Generate a UUID (version 4).

static Uuid
uuid7(DateTimeInterface|null $time = null)

Generate a UUID (version 7).

static Uuid
orderedUuid()

Generate a time-ordered UUID (version 7).

static Uuid
factoryUuid()

Resolve a UUID from the custom factory, coercing strings to Uuid instances.

static void
createUuidsUsing(callable|null $factory = null)

Set the callable that will be used to generate UUIDs.

static void
createUuidsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate UUIDs.

static Uuid
freezeUuids(Closure|null $callback = null)

Always return the same UUID when generating new UUIDs.

static void
createUuidsNormally()

Indicate that UUIDs should be created normally and not using a custom factory.

static Ulid
ulid(DateTimeInterface|null $time = null)

Generate a ULID.

static void
createUlidsNormally()

Indicate that ULIDs should be created normally and not using a custom factory.

static void
createUlidsUsing(callable|null $factory = null)

Set the callable that will be used to generate ULIDs.

static void
createUlidsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate ULIDs.

static Ulid
freezeUlids(Closure|null $callback = null)

Always return the same ULID when generating new ULIDs.

static void
flushCache()

Remove all strings from the casing caches.

static void
resetFactoryState()

Return all factory functions to their default state.

static void
flushState()

Flush all static state.

Details

in Macroable at line 28
static void macro(string $name, callable|object $macro)

Register a custom macro.

Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.

Parameters

string $name
callable|object $macro

Return Value

void

in Macroable at line 41
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 68
static void flushMacros()

Flush the existing macros.

Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 60
static Stringable of(mixed $string)

Get a new stringable object from the given string.

Parameters

mixed $string

Return Value

Stringable

at line 68
static Stringable trans(string $key, array $replace = [], string|null $locale = null)

Translate the given message and get a new stringable object.

Parameters

string $key
array $replace
string|null $locale

Return Value

Stringable

at line 76
static string after(string $subject, string|int|float|bool|Stringable|null $search)

Return the remainder of a string after the first occurrence of a given value.

Parameters

string $subject
string|int|float|bool|Stringable|null $search

Return Value

string

at line 86
static string afterLast(string $subject, string|int|float|bool|Stringable|null $search)

Return the remainder of a string after the last occurrence of a given value.

Parameters

string $subject
string|int|float|bool|Stringable|null $search

Return Value

string

at line 106
static string ascii(string|int|float|bool|Stringable|null $value, string $language = 'en')

Transliterate a UTF-8 value to ASCII.

Parameters

string|int|float|bool|Stringable|null $value
string $language

Return Value

string

at line 114
static string transliterate(string|int|float|bool|Stringable|null $string, string|null $unknown = '?', bool $strict = false)

Transliterate a string to its closest ASCII representation.

Parameters

string|int|float|bool|Stringable|null $string
string|null $unknown
bool $strict

Return Value

string

at line 122
static string before(string $subject, string|int|float|bool|Stringable|null $search)

Get the portion of a string before the first occurrence of a given value.

Parameters

string $subject
string|int|float|bool|Stringable|null $search

Return Value

string

at line 138
static string beforeLast(string $subject, string|int|float|bool|Stringable|null $search)

Get the portion of a string before the last occurrence of a given value.

Parameters

string $subject
string|int|float|bool|Stringable|null $search

Return Value

string

at line 159
static string between(string $subject, string|int|float|bool|Stringable|null $from, string|int|float|bool|Stringable|null $to)

Get the portion of a string between two given values.

Parameters

string $subject
string|int|float|bool|Stringable|null $from
string|int|float|bool|Stringable|null $to

Return Value

string

at line 174
static string betweenFirst(string $subject, string|int|float|bool|Stringable|null $from, string|int|float|bool|Stringable|null $to)

Get the smallest possible portion of a string between two given values.

Parameters

string $subject
string|int|float|bool|Stringable|null $from
string|int|float|bool|Stringable|null $to

Return Value

string

at line 191
static string camel(string $value)

Convert a value to camel case.

Parameters

string $value

Return Value

string

at line 199
static string|false charAt(string $subject, int $index)

Get the character at the specified index.

Parameters

string $subject
int $index

Return Value

string|false

at line 215
static string chopStart(string $subject, string|array $needle)

Remove the given string(s) if it exists at the start of the haystack.

Parameters

string $subject
string|array $needle

Return Value

string

at line 231
static string chopEnd(string $subject, string|array $needle)

Remove the given string(s) if it exists at the end of the haystack.

Parameters

string $subject
string|array $needle

Return Value

string

at line 253
static bool contains(string $haystack, string|iterable $needles, bool $ignoreCase = false)

Determine if a given string contains a given substring.

Parameters

string $haystack
string|iterable $needles
bool $ignoreCase

Return Value

bool

at line 282
static bool containsAll(string $haystack, iterable $needles, bool $ignoreCase = false)

Determine if a given string contains all array values.

Parameters

string $haystack
iterable $needles
bool $ignoreCase

Return Value

bool

at line 303
static bool doesntContain(string $haystack, string|iterable $needles, bool $ignoreCase = false)

Determine if a given string doesn't contain a given substring.

Parameters

string $haystack
string|iterable $needles
bool $ignoreCase

Return Value

bool

at line 314
static string convertCase(string $string, int $mode = MB_CASE_FOLD, string|null $encoding = 'UTF-8')

Convert the case of a string.

Parameters

string $string
int $mode
string|null $encoding

Return Value

string

at line 322
static string counted(string $value, int|array|Countable $count)

Get the plural form of an English word with the count prepended.

Parameters

string $value
int|array|Countable $count

Return Value

string

at line 333
static string deduplicate(string $string, array|string $characters = ' ')

Replace consecutive instances of a given character with a single character in the given string.

Parameters

string $string
array|string $characters

Return Value

string

at line 352
static bool endsWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string ends with a given substring.

Parameters

string|int|float|bool|Stringable|null $haystack
string|int|float|bool|Stringable|iterable|null $needles

Return Value

bool

at line 381
static bool doesntEndWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string doesn't end with a given substring.

Parameters

string|int|float|bool|Stringable|null $haystack
string|int|float|bool|Stringable|iterable|null $needles

Return Value

bool

at line 391
static string|null excerpt(string|int|float|bool|Stringable|null $text, string|int|float|bool|Stringable|null $phrase = '', array $options = [])

Extract an excerpt from text that matches the first instance of a phrase.

Parameters

string|int|float|bool|Stringable|null $text
string|int|float|bool|Stringable|null $phrase
array $options

Return Value

string|null

at line 427
static string finish(string $value, string $cap)

Cap a string with a single instance of a given value.

Parameters

string $value
string $cap

Return Value

string

at line 439
static string wrap(string $value, string $before, string|null $after = null)

Wrap the string with the given strings.

Parameters

string $value
string $before
string|null $after

Return Value

string

at line 447
static string unwrap(string $value, string $before, string|null $after = null)

Unwrap the string with the given strings.

Parameters

string $value
string $before
string|null $after

Return Value

string

at line 470
static bool is(string|int|float|bool|Stringable|iterable|null $pattern, string|int|float|bool|Stringable|null $value, bool $ignoreCase = false)

Determine if a given string matches a given pattern.

Parameters

string|int|float|bool|Stringable|iterable|null $pattern
string|int|float|bool|Stringable|null $value
bool $ignoreCase

Return Value

bool

at line 510
static bool isAscii(string|int|float|bool|Stringable|null $value)

Determine if a given string is 7 bit ASCII.

Parameters

string|int|float|bool|Stringable|null $value

Return Value

bool

at line 520
static bool isJson(mixed $value)

Determine if a given value is valid JSON.

Parameters

mixed $value

Return Value

bool

at line 536
static bool isUrl(mixed $value, array $protocols = [])

Determine if a given value is a valid URL.

Parameters

mixed $value
array $protocols

Return Value

bool

at line 590
static bool isUuid(mixed $value, int|string|null $version = null)

Determine if a given value is a valid UUID.

Parameters

mixed $value
int|string|null $version

Return Value

bool

at line 620
static bool isUlid(mixed $value)

Determine if a given value is a valid ULID.

Parameters

mixed $value

Return Value

bool

at line 634
static string kebab(string $value)

Convert a string to kebab case.

Parameters

string $value

Return Value

string

at line 644
static int length(string $value, string|null $encoding = null)

Return the length of the given string.

Parameters

string $value
string|null $encoding

Return Value

int

at line 652
static string limit(string $value, int $limit = 100, string $end = '...', bool $preserveWords = false)

Limit the number of characters in a string.

Parameters

string $value
int $limit
string $end
bool $preserveWords

Return Value

string

at line 678
static string lower(string $value)

Convert the given string to lower-case.

Parameters

string $value

Return Value

string

at line 686
static string words(string $value, int $words = 100, string $end = '...')

Limit the number of words in a string.

Parameters

string $value
int $words
string $end

Return Value

string

at line 703
static string markdown(string|int|float|bool|Stringable|null $string, array $options = [], array $extensions = [])

Convert GitHub flavored Markdown into HTML.

Parameters

string|int|float|bool|Stringable|null $string
array $options
array $extensions

Return Value

string

at line 724
static string inlineMarkdown(string|int|float|bool|Stringable|null $string, array $options = [], array $extensions = [])

Convert inline Markdown into HTML.

Parameters

string|int|float|bool|Stringable|null $string
array $options
array $extensions

Return Value

string

at line 745
static string mask(string $string, string|Stringable $character, int $index, int|null $length = null, string $encoding = 'UTF-8')

Mask a portion of a string with a repeated character.

Parameters

string $string
string|Stringable $character
int $index
int|null $length
string $encoding

Return Value

string

at line 776
static string match(string $pattern, string $subject)

Get the string matching the given pattern.

Parameters

string $pattern
string $subject

Return Value

string

at line 793
static bool isMatch(string|iterable $pattern, string $value)

Determine if a given string matches a given pattern.

Parameters

string|iterable $pattern
string $value

Return Value

bool

at line 813
static Collection matchAll(string $pattern, string $subject)

Get the string matching the given pattern.

Parameters

string $pattern
string $subject

Return Value

Collection

at line 830
static string|array numbers(string|array $value)

Remove all non-numeric characters from a string.

Parameters

string|array $value

Return Value

string|array

at line 838
static string padBoth(string $value, int $length, string $pad = ' ')

Pad both sides of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

at line 846
static string padLeft(string $value, int $length, string $pad = ' ')

Pad the left side of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

at line 854
static string padRight(string $value, int $length, string $pad = ' ')

Pad the right side of a string with another.

Parameters

string $value
int $length
string $pad

Return Value

string

at line 864
static array parseCallback(string $callback, string|null $default = null)

Parse a Class[@]method style callback into class and method.

Parameters

string $callback
string|null $default

Return Value

array

at line 883
static string plural(string $value, int|array|Countable $count = 2, bool $prependCount = false)

Get the plural form of an English word.

Parameters

string $value
int|array|Countable $count
bool $prependCount

Return Value

string

at line 895
static string pluralStudly(string $value, int|array|Countable $count = 2)

Pluralize the last word of an English, studly caps case string.

Parameters

string $value
int|array|Countable $count

Return Value

string

at line 907
static string pluralPascal(string $value, int|array|Countable $count = 2)

Pluralize the last word of an English, Pascal caps case string.

Parameters

string $value
int|array|Countable $count

Return Value

string

at line 917
static string password(int $length = 32, bool $letters = true, bool $numbers = true, bool $symbols = true, bool $spaces = false)

Generate a random, secure password.

Parameters

int $length
bool $letters
bool $numbers
bool $symbols
bool $spaces

Return Value

string

at line 955
static int|false position(string $haystack, string $needle, int $offset = 0, string|null $encoding = null)

Find the multi-byte safe position of the first occurrence of a given substring in a string.

Parameters

string $haystack
string $needle
int $offset
string|null $encoding

Return Value

int|false

at line 963
static string random(int $length = 16)

Generate a more truly "random" alpha-numeric string.

Parameters

int $length

Return Value

string

at line 990
static void createRandomStringsUsing(callable|null $factory = null)

Set the callable that will be used to generate random strings.

Tests only. The factory persists in a static property for the worker lifetime and affects every subsequent random string generation.

Parameters

callable|null $factory

Return Value

void

at line 1004
static void createRandomStringsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate random strings.

Tests only. The sequence factory persists in a static property for the worker lifetime and affects every subsequent random string generation.

Parameters

array $sequence
callable|null $whenMissing

Return Value

void

at line 1040
static void createRandomStringsNormally()

Indicate that random strings should be created normally and not using a custom factory.

Tests only. Clears the worker-wide random string factory; concurrent coroutines may observe different random string behavior depending on timing.

Return Value

void

at line 1048
static string repeat(string $string, int $times)

Repeat the given string.

Parameters

string $string
int $times

Return Value

string

at line 1058
static string replaceArray(string $search, iterable $replace, string $subject)

Replace a given value in the string sequentially with an array.

Parameters

string $search
iterable $replace
string $subject

Return Value

string

at line 1097
static string|array replace(string|iterable $search, string|iterable $replace, string|iterable $subject, bool $caseSensitive = true)

Replace the given value in the given string.

Parameters

string|iterable $search
string|iterable $replace
string|iterable $subject
bool $caseSensitive

Return Value

string|array

at line 1124
static protected string|array replaceWhileIgnoringCase(string|array $search, string|array $replace, string|array $subject)

Replace the given value in the given string regardless of case.

Parameters

string|array $search
string|array $replace
string|array $subject

Return Value

string|array

at line 1170
static string replaceFirst(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the first occurrence of a given value in the string.

Parameters

string|int|float|bool|Stringable|null $search
string $replace
string $subject

Return Value

string

at line 1190
static string replaceStart(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the first occurrence of the given value if it appears at the start of the string.

Parameters

string|int|float|bool|Stringable|null $search
string $replace
string $subject

Return Value

string

at line 1208
static string replaceLast(string $search, string $replace, string $subject)

Replace the last occurrence of a given value in the string.

Parameters

string $search
string $replace
string $subject

Return Value

string

at line 1226
static string replaceEnd(string|int|float|bool|Stringable|null $search, string $replace, string $subject)

Replace the last occurrence of a given value if it appears at the end of the string.

Parameters

string|int|float|bool|Stringable|null $search
string $replace
string $subject

Return Value

string

at line 1249
static string|array|null replaceMatches(string|array $pattern, Closure|array|string $replace, string|array $subject, int $limit = -1)

Replace the patterns matching the given regular expression.

Parameters

string|array $pattern
Closure|array|string $replace
string|array $subject
int $limit

Return Value

string|array|null

at line 1263
static string remove(string|iterable $search, string $subject, bool $caseSensitive = true)

Remove any occurrence of the given string in the subject.

Parameters

string|iterable $search
string $subject
bool $caseSensitive

Return Value

string

at line 1277
static string reverse(string $value)

Reverse the given string.

Parameters

string $value

Return Value

string

at line 1287
static string start(string $value, string $prefix)

Begin a string with a single instance of a given value.

Parameters

string $value
string $prefix

Return Value

string

at line 1299
static string upper(string $value)

Convert the given string to upper-case.

Parameters

string $value

Return Value

string

at line 1307
static string title(string $value)

Convert the given string to proper case.

Parameters

string $value

Return Value

string

at line 1315
static string headline(string $value)

Convert the given string to proper case for each word.

Parameters

string $value

Return Value

string

at line 1331
static string initials(string $value, bool $capitalize = false)

Get the "initials" representing each word in the provided string, optionally capitalizing.

Parameters

string $value
bool $capitalize

Return Value

string

at line 1347
static string apa(string $value)

Convert the given string to APA-style title case.

See: https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case

Parameters

string $value

Return Value

string

at line 1398
static string singular(string $value)

Get the singular form of an English word.

Parameters

string $value

Return Value

string

at line 1408
static string slug(string|int|float|bool|Stringable|null $title, string $separator = '-', string|null $language = 'en', array $dictionary = ['@' => 'at'])

Generate a URL friendly "slug" from a given string.

Parameters

string|int|float|bool|Stringable|null $title
string $separator
string|null $language
array $dictionary

Return Value

string

at line 1438
static string snake(string $value, string $delimiter = '_')

Convert a string to snake case.

Parameters

string $value
string $delimiter

Return Value

string

at line 1452
static string trim(string $value, string|null $charlist = null)

Remove all whitespace from both ends of a string.

Parameters

string $value
string|null $charlist

Return Value

string

at line 1481
static string ltrim(string $value, string|null $charlist = null)

Remove all whitespace from the beginning of a string.

Parameters

string $value
string|null $charlist

Return Value

string

at line 1495
static string rtrim(string $value, string|null $charlist = null)

Remove all whitespace from the end of a string.

Parameters

string $value
string|null $charlist

Return Value

string

at line 1509
static string squish(string $value)

Remove all "extra" blank space from the given string.

Parameters

string $value

Return Value

string

at line 1522
static bool startsWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string starts with a given substring.

Parameters

string|int|float|bool|Stringable|null $haystack
string|int|float|bool|Stringable|iterable|null $needles

Return Value

bool

at line 1553
static bool doesntStartWith(string|int|float|bool|Stringable|null $haystack, string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string doesn't start with a given substring.

Parameters

string|int|float|bool|Stringable|null $haystack
string|int|float|bool|Stringable|iterable|null $needles

Return Value

bool

at line 1564
static string studly(string $value, bool $normalize = false)

Convert a value to studly caps case.

Parameters

string $value
bool $normalize

when true, all-uppercase words (e.g. acronyms) are lowercased before conversion so "CBOR" becomes "Cbor" instead of "CBOR"

Return Value

string

at line 1587
static string pascal(string $value, bool $normalize = false)

Convert a value to Pascal case.

Parameters

string $value
bool $normalize

when true, all-uppercase words (e.g. acronyms) are lowercased before conversion so "CBOR" becomes "Cbor" instead of "CBOR"

Return Value

string

at line 1595
static string substr(string $string, int $start, int|null $length = null, string $encoding = 'UTF-8')

Return the portion of the string specified by the start and length parameters.

Parameters

string $string
int $start
int|null $length
string $encoding

Return Value

string

at line 1603
static int substrCount(string $haystack, string $needle, int $offset = 0, int|null $length = null)

Return the number of substring occurrences.

Parameters

string $haystack
string $needle
int $offset
int|null $length

Return Value

int

at line 1621
static string|array substrReplace(string|array $string, string|array $replace, int|array $offset = 0, int|array|null $length = null)

Replace text within a portion of a string.

Parameters

string|array $string
string|array $replace
int|array $offset
int|array|null $length

Return Value

string|array

at line 1673
static string swap(array $map, string $subject)

Swap multiple keywords in a string with other keywords.

Parameters

array $map
string $subject

Return Value

string

at line 1681
static string take(string $string, int $limit)

Take the first or last {$limit} characters of a string.

Parameters

string $string
int $limit

Return Value

string

at line 1695
static string toBase64(string $string)

Convert the given string to Base64 encoding.

Parameters

string $string

Return Value

string

at line 1705
static string|false fromBase64(string $string, bool $strict = false)

Decode the given Base64 encoded string.

Parameters

string $string
bool $strict

Return Value

string|false

at line 1715
static string lcfirst(string $string)

Make a string's first character lowercase.

Parameters

string $string

Return Value

string

at line 1725
static string ucfirst(string $string)

Make a string's first character uppercase.

Parameters

string $string

Return Value

string

at line 1735
static string ucwords(string $string, string $separators = " \t\r\n\f\v")

Capitalize the first character of each word in a string.

Parameters

string $string
string $separators

Return Value

string

at line 1753
static array ucsplit(string $string)

Split a string into pieces by uppercase characters.

Parameters

string $string

Return Value

array

at line 1763
static int wordCount(string $string, string|null $characters = null)

Get the number of words a string contains.

Parameters

string $string
string|null $characters

Return Value

int

at line 1771
static string wordWrap(string $string, int $characters = 75, string $break = "\n", bool $cutLongWords = false)

Wrap a string to a given number of characters.

Parameters

string $string
int $characters
string $break
bool $cutLongWords

Return Value

string

at line 1805
static Uuid uuid()

Generate a UUID (version 4).

Return Value

Uuid

at line 1815
static Uuid uuid7(DateTimeInterface|null $time = null)

Generate a UUID (version 7).

Parameters

DateTimeInterface|null $time

Return Value

Uuid

at line 1831
static Uuid orderedUuid()

Generate a time-ordered UUID (version 7).

Return Value

Uuid

at line 1841
static protected Uuid factoryUuid()

Resolve a UUID from the custom factory, coercing strings to Uuid instances.

Return Value

Uuid

at line 1856
static void createUuidsUsing(callable|null $factory = null)

Set the callable that will be used to generate UUIDs.

Tests only. The factory persists in a static property for the worker lifetime and affects every subsequent UUID generation.

Parameters

callable|null $factory

Return Value

void

at line 1870
static void createUuidsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate UUIDs.

Tests only. The sequence factory persists in a static property for the worker lifetime and affects every subsequent UUID generation.

Parameters

array $sequence
callable|null $whenMissing

Return Value

void

at line 1908
static Uuid freezeUuids(Closure|null $callback = null)

Always return the same UUID when generating new UUIDs.

Tests only unless a callback is supplied. Without a callback, the factory persists in a static property for the worker lifetime and affects every subsequent UUID generation.

Parameters

Closure|null $callback

Return Value

Uuid

at line 1931
static void createUuidsNormally()

Indicate that UUIDs should be created normally and not using a custom factory.

Tests only. Clears the worker-wide UUID factory; concurrent coroutines may observe different UUID behavior depending on timing.

Return Value

void

at line 1939
static Ulid ulid(DateTimeInterface|null $time = null)

Generate a ULID.

Parameters

DateTimeInterface|null $time

Return Value

Ulid

at line 1958
static void createUlidsNormally()

Indicate that ULIDs should be created normally and not using a custom factory.

Tests only. Clears the worker-wide ULID factory; concurrent coroutines may observe different ULID behavior depending on timing.

Return Value

void

at line 1971
static void createUlidsUsing(callable|null $factory = null)

Set the callable that will be used to generate ULIDs.

Tests only. The factory persists in a static property for the worker lifetime and affects every subsequent ULID generation.

Parameters

callable|null $factory

Return Value

void

at line 1985
static void createUlidsUsingSequence(array $sequence, callable|null $whenMissing = null)

Set the sequence that will be used to generate ULIDs.

Tests only. The sequence factory persists in a static property for the worker lifetime and affects every subsequent ULID generation.

Parameters

array $sequence
callable|null $whenMissing

Return Value

void

at line 2023
static Ulid freezeUlids(Closure|null $callback = null)

Always return the same ULID when generating new ULIDs.

Tests only unless a callback is supplied. Without a callback, the factory persists in a static property for the worker lifetime and affects every subsequent ULID generation.

Parameters

Closure|null $callback

Return Value

Ulid

at line 2043
static void flushCache()

Remove all strings from the casing caches.

Return Value

void

at line 2054
static void resetFactoryState()

Return all factory functions to their default state.

Tests only. Clears the worker-wide random string, UUID, and ULID factories, affecting generation in every coroutine.

Return Value

void

at line 2064
static void flushState()

Flush all static state.

Return Value

void