class Stringable implements JsonSerializable, ArrayAccess, Stringable

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string $value

The underlying string value.

Methods

mixed
when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

mixed
unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

never
dd(mixed ...$args)

Dump the given arguments and terminate execution.

from  Dumpable
dump(mixed ...$args)

Dump the string.

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.

mixed
tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

from  Tappable
__construct(mixed $value = '')

Create a new instance of the class.

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

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

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

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

append(string|int|float|bool|Stringable|null ...$values)

Append the given values to the string.

newLine(int $count = 1)

Append a new line to the string.

ascii(string $language = 'en')

Transliterate a UTF-8 value to ASCII.

basename(string $suffix = '')

Get the trailing name component of the path.

string|false
charAt(mixed $index)

Get the character at the specified index.

chopStart(string|array $needle)

Remove the given string if it exists at the start of the current string.

chopEnd(string|array $needle)

Remove the given string if it exists at the end of the current string.

classBasename()

Get the basename of the class path.

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

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

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

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

between(string $from, string $to)

Get the portion of a string between two given values.

betweenFirst(string $from, string $to)

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

camel()

Convert a value to camel case.

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

Determine if a given string contains a given substring.

bool
containsAll(iterable $needles, bool $ignoreCase = false)

Determine if a given string contains all array values.

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

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

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

Convert the case of a string.

counted(int|array|Countable $count)

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

deduplicate(string $character = ' ')

Replace consecutive instances of a given character with a single character.

dirname(int $levels = 1)

Get the parent directory's path.

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

Determine if a given string ends with a given substring.

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

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

bool
exactly(mixed $value)

Determine if the string is an exact match with the given value.

string|null
excerpt(string $phrase = '', array $options = [])

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

explode(string $delimiter, int $limit = PHP_INT_MAX)

Explode the string into a collection.

split(string|int $pattern, int $limit = -1, int $flags = 0)

Split a string using a regular expression or by length.

finish(string $cap)

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

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

Determine if a given string matches a given pattern.

bool
isAscii()

Determine if a given string is 7 bit ASCII.

bool
isJson()

Determine if a given string is valid JSON.

bool
isUrl(array $protocols = [])

Determine if a given value is a valid URL.

bool
isUuid(int|string|null $version = null)

Determine if a given string is a valid UUID.

bool
isUlid()

Determine if a given string is a valid ULID.

bool
isEmpty()

Determine if the given string is empty.

bool
isNotEmpty()

Determine if the given string is not empty.

kebab()

Convert a string to kebab case.

int
length(string|null $encoding = null)

Return the length of the given string.

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

Limit the number of characters in a string.

lower()

Convert the given string to lower-case.

markdown(array $options = [], array $extensions = [])

Convert GitHub flavored Markdown into HTML.

inlineMarkdown(array $options = [], array $extensions = [])

Convert inline Markdown into HTML.

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

Masks a portion of a string with a repeated character.

match(string $pattern)

Get the string matching the given pattern.

bool
isMatch(string|iterable $pattern)

Determine if a given string matches a given pattern.

matchAll(string $pattern)

Get the string matching the given pattern.

bool
test(string $pattern)

Determine if the string matches the given pattern.

numbers()

Remove all non-numeric characters from a string.

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

Pad both sides of the string with another.

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

Pad the left side of the string with another.

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

Pad the right side of the string with another.

array
parseCallback(string|null $default = null)

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

pipe(callable $callback)

Call the given callback and return a new string.

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

Get the plural form of an English word.

pluralStudly(int|array|Countable $count = 2)

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

pluralPascal(int|array|Countable $count = 2)

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

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

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

prepend(string ...$values)

Prepend the given values to the string.

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

Remove any occurrence of the given string in the subject.

reverse()

Reverse the string.

repeat(int $times)

Repeat the string.

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

Replace the given value in the given string.

replaceArray(string $search, iterable $replace)

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

replaceFirst(string $search, string $replace)

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

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

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

replaceLast(string $search, string $replace)

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

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

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

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

Replace the patterns matching the given regular expression.

scan(string $format)

Parse input from a string to a collection, according to a format.

squish()

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

start(string $prefix)

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

stripTags(array|string|null $allowedTags = null)

Strip HTML and PHP tags from the given string.

upper()

Convert the given string to upper-case.

title()

Convert the given string to proper case.

headline()

Convert the given string to proper case for each word.

initials(bool $capitalize = false)

Convert the given string to only its initials.

apa()

Convert the given string to APA-style title case.

transliterate(string|null $unknown = '?', bool|null $strict = false)

Transliterate a string to its closest ASCII representation.

singular()

Get the singular form of an English word.

slug(string $separator = '-', string|null $language = 'en', array $dictionary = ['@' => 'at'])

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

snake(string $delimiter = '_')

Convert a string to snake case.

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

Determine if a given string starts with a given substring.

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

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

studly(bool $normalize = false)

Convert a value to studly caps case.

pascal(bool $normalize = false)

Convert the string to Pascal case.

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

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

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

Returns the number of substring occurrences.

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

Replace text within a portion of a string.

swap(array $map)

Swap multiple keywords in a string with other keywords.

take(int $limit)

Take the first or last {$limit} characters.

trim(string|null $characters = null)

Trim the string of the given characters.

ltrim(string|null $characters = null)

Left trim the string of the given characters.

rtrim(string|null $characters = null)

Right trim the string of the given characters.

lcfirst()

Make a string's first character lowercase.

ucfirst()

Make a string's first character uppercase.

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

Capitalize the first character of each word in a string.

ucsplit()

Split a string by uppercase characters.

mixed
whenContains(string|iterable $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string contains a given substring.

mixed
whenContainsAll(iterable $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string contains all array values.

mixed
whenEmpty(callable $callback, callable|null $default = null)

Execute the given callback if the string is empty.

mixed
whenNotEmpty(callable $callback, callable|null $default = null)

Execute the given callback if the string is not empty.

mixed
whenEndsWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string ends with a given substring.

mixed
whenDoesntEndWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string doesn't end with a given substring.

mixed
whenExactly(string $value, callable $callback, callable|null $default = null)

Execute the given callback if the string is an exact match with the given value.

mixed
whenNotExactly(string $value, callable $callback, callable|null $default = null)

Execute the given callback if the string is not an exact match with the given value.

mixed
whenIs(string|int|float|bool|Stringable|iterable|null $pattern, callable $callback, callable|null $default = null)

Execute the given callback if the string matches a given pattern.

mixed
whenIsAscii(callable $callback, callable|null $default = null)

Execute the given callback if the string is 7 bit ASCII.

mixed
whenIsUuid(callable $callback, callable|null $default = null)

Execute the given callback if the string is a valid UUID.

mixed
whenIsUlid(callable $callback, callable|null $default = null)

Execute the given callback if the string is a valid ULID.

mixed
whenStartsWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string starts with a given substring.

mixed
whenDoesntStartWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string doesn't start with a given substring.

mixed
whenTest(string $pattern, callable $callback, callable|null $default = null)

Execute the given callback if the string matches the given pattern.

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

Limit the number of words in a string.

int
wordCount(string|null $characters = null)

Get the number of words a string contains.

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

Wrap a string to a given number of characters.

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

Wrap the string with the given strings.

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

Unwrap the string with the given strings.

toHtmlString()

Convert the string into a HtmlString instance.

toBase64()

Convert the string to Base64 encoding.

fromBase64(bool $strict = false)

Decode the Base64 encoded string.

hash(string $algorithm)

Hash the string using the given algorithm.

encrypt(bool $serialize = false)

Encrypt the string.

decrypt(bool $serialize = false)

Decrypt the string.

string
value()

Get the underlying string value.

string
toString()

Get the underlying string value.

int
toInteger(int $base = 10)

Get the underlying string value as an integer.

float
toFloat()

Get the underlying string value as a float.

bool
toBoolean()

Get the underlying string value as a boolean.

CarbonInterface|null
toDate(string|null $format = null, string|null $tz = null)

Get the underlying string value as a Carbon instance.

Uri
toUri()

Get the underlying string value as a Uri instance.

string
jsonSerialize()

Convert the object to a string when JSON encoded.

bool
offsetExists(mixed $offset)

Determine if the given offset exists.

string
offsetGet(mixed $offset)

Get the value at the given offset.

void
offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

void
offsetUnset(mixed $offset)

Unset the value at the given offset.

static void
flushState()

Flush all static state.

mixed
__get(string $key)

Proxy dynamic properties onto methods.

string
__toString()

Get the raw string value.

Details

in Conditionable at line 23
mixed when(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Conditionable at line 56
mixed unless(mixed $value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

mixed $value
callable|null $callback
callable|null $default

Return Value

mixed

in Dumpable at line 12
never dd(mixed ...$args)

Dump the given arguments and terminate execution.

Parameters

mixed ...$args

Return Value

never

at line 1111
Stringable dump(mixed ...$args)

Dump the string.

Parameters

mixed ...$args

Return Value

Stringable

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

in Tappable at line 15
mixed tap(callable|null $callback = null)

Call the given Closure with this instance then return the instance.

Parameters

callable|null $callback

Return Value

mixed

at line 34
__construct(mixed $value = '')

Create a new instance of the class.

Parameters

mixed $value

at line 42
Stringable after(string|int|float|bool|Stringable|null $search)

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

Parameters

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

Return Value

Stringable

at line 50
Stringable afterLast(string|int|float|bool|Stringable|null $search)

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

Parameters

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

Return Value

Stringable

at line 58
Stringable append(string|int|float|bool|Stringable|null ...$values)

Append the given values to the string.

Parameters

string|int|float|bool|Stringable|null ...$values

Return Value

Stringable

at line 66
Stringable newLine(int $count = 1)

Append a new line to the string.

Parameters

int $count

Return Value

Stringable

at line 74
Stringable ascii(string $language = 'en')

Transliterate a UTF-8 value to ASCII.

Parameters

string $language

Return Value

Stringable

at line 82
Stringable basename(string $suffix = '')

Get the trailing name component of the path.

Parameters

string $suffix

Return Value

Stringable

at line 90
string|false charAt(mixed $index)

Get the character at the specified index.

Parameters

mixed $index

Return Value

string|false

at line 98
Stringable chopStart(string|array $needle)

Remove the given string if it exists at the start of the current string.

Parameters

string|array $needle

Return Value

Stringable

at line 106
Stringable chopEnd(string|array $needle)

Remove the given string if it exists at the end of the current string.

Parameters

string|array $needle

Return Value

Stringable

at line 114
Stringable classBasename()

Get the basename of the class path.

Return Value

Stringable

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

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

Parameters

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

Return Value

Stringable

at line 130
Stringable beforeLast(string|int|float|bool|Stringable|null $search)

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

Parameters

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

Return Value

Stringable

at line 138
Stringable between(string $from, string $to)

Get the portion of a string between two given values.

Parameters

string $from
string $to

Return Value

Stringable

at line 146
Stringable betweenFirst(string $from, string $to)

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

Parameters

string $from
string $to

Return Value

Stringable

at line 154
Stringable camel()

Convert a value to camel case.

Return Value

Stringable

at line 164
bool contains(string|iterable $needles, bool $ignoreCase = false)

Determine if a given string contains a given substring.

Parameters

string|iterable $needles
bool $ignoreCase

Return Value

bool

at line 174
bool containsAll(iterable $needles, bool $ignoreCase = false)

Determine if a given string contains all array values.

Parameters

iterable $needles
bool $ignoreCase

Return Value

bool

at line 184
bool doesntContain(string|iterable $needles, bool $ignoreCase = false)

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

Parameters

string|iterable $needles
bool $ignoreCase

Return Value

bool

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

Convert the case of a string.

Parameters

int $mode
string|null $encoding

Return Value

Stringable

at line 200
Stringable counted(int|array|Countable $count)

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

Parameters

int|array|Countable $count

Return Value

Stringable

at line 208
Stringable deduplicate(string $character = ' ')

Replace consecutive instances of a given character with a single character.

Parameters

string $character

Return Value

Stringable

at line 216
Stringable dirname(int $levels = 1)

Get the parent directory's path.

Parameters

int $levels

Return Value

Stringable

at line 226
bool endsWith(string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string ends with a given substring.

Parameters

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

Return Value

bool

at line 236
bool doesntEndWith(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|iterable|null $needles

Return Value

bool

at line 244
bool exactly(mixed $value)

Determine if the string is an exact match with the given value.

Parameters

mixed $value

Return Value

bool

at line 256
string|null excerpt(string $phrase = '', array $options = [])

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

Parameters

string $phrase
array $options

Return Value

string|null

at line 266
Collection explode(string $delimiter, int $limit = PHP_INT_MAX)

Explode the string into a collection.

Parameters

string $delimiter
int $limit

Return Value

Collection

at line 276
Collection split(string|int $pattern, int $limit = -1, int $flags = 0)

Split a string using a regular expression or by length.

Parameters

string|int $pattern
int $limit
int $flags

Return Value

Collection

at line 290
Stringable finish(string $cap)

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

Parameters

string $cap

Return Value

Stringable

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

Determine if a given string matches a given pattern.

Parameters

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

Return Value

bool

at line 308
bool isAscii()

Determine if a given string is 7 bit ASCII.

Return Value

bool

at line 316
bool isJson()

Determine if a given string is valid JSON.

Return Value

bool

at line 324
bool isUrl(array $protocols = [])

Determine if a given value is a valid URL.

Parameters

array $protocols

Return Value

bool

at line 334
bool isUuid(int|string|null $version = null)

Determine if a given string is a valid UUID.

Parameters

int|string|null $version

Return Value

bool

at line 342
bool isUlid()

Determine if a given string is a valid ULID.

Return Value

bool

at line 350
bool isEmpty()

Determine if the given string is empty.

Return Value

bool

at line 358
bool isNotEmpty()

Determine if the given string is not empty.

Return Value

bool

at line 366
Stringable kebab()

Convert a string to kebab case.

Return Value

Stringable

at line 374
int length(string|null $encoding = null)

Return the length of the given string.

Parameters

string|null $encoding

Return Value

int

at line 382
Stringable limit(int $limit = 100, string $end = '...', bool $preserveWords = false)

Limit the number of characters in a string.

Parameters

int $limit
string $end
bool $preserveWords

Return Value

Stringable

at line 390
Stringable lower()

Convert the given string to lower-case.

Return Value

Stringable

at line 398
Stringable markdown(array $options = [], array $extensions = [])

Convert GitHub flavored Markdown into HTML.

Parameters

array $options
array $extensions

Return Value

Stringable

at line 406
Stringable inlineMarkdown(array $options = [], array $extensions = [])

Convert inline Markdown into HTML.

Parameters

array $options
array $extensions

Return Value

Stringable

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

Masks a portion of a string with a repeated character.

Parameters

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

Return Value

Stringable

at line 422
Stringable match(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Stringable

at line 432
bool isMatch(string|iterable $pattern)

Determine if a given string matches a given pattern.

Parameters

string|iterable $pattern

Return Value

bool

at line 440
Collection matchAll(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Collection

at line 448
bool test(string $pattern)

Determine if the string matches the given pattern.

Parameters

string $pattern

Return Value

bool

at line 456
Stringable numbers()

Remove all non-numeric characters from a string.

Return Value

Stringable

at line 464
Stringable padBoth(int $length, string $pad = ' ')

Pad both sides of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

at line 472
Stringable padLeft(int $length, string $pad = ' ')

Pad the left side of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

at line 480
Stringable padRight(int $length, string $pad = ' ')

Pad the right side of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

at line 490
array parseCallback(string|null $default = null)

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

Parameters

string|null $default

Return Value

array

at line 498
Stringable pipe(callable $callback)

Call the given callback and return a new string.

Parameters

callable $callback

Return Value

Stringable

at line 506
Stringable plural(int|array|Countable $count = 2, bool $prependCount = false)

Get the plural form of an English word.

Parameters

int|array|Countable $count
bool $prependCount

Return Value

Stringable

at line 514
Stringable pluralStudly(int|array|Countable $count = 2)

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

Parameters

int|array|Countable $count

Return Value

Stringable

at line 522
Stringable pluralPascal(int|array|Countable $count = 2)

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

Parameters

int|array|Countable $count

Return Value

Stringable

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

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

Parameters

string $needle
int $offset
string|null $encoding

Return Value

int|false

at line 538
Stringable prepend(string ...$values)

Prepend the given values to the string.

Parameters

string ...$values

Return Value

Stringable

at line 548
Stringable remove(string|iterable $search, bool $caseSensitive = true)

Remove any occurrence of the given string in the subject.

Parameters

string|iterable $search
bool $caseSensitive

Return Value

Stringable

at line 556
Stringable reverse()

Reverse the string.

Return Value

Stringable

at line 564
Stringable repeat(int $times)

Repeat the string.

Parameters

int $times

Return Value

Stringable

at line 575
Stringable replace(string|iterable $search, string|iterable $replace, bool $caseSensitive = true)

Replace the given value in the given string.

Parameters

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

Return Value

Stringable

at line 585
Stringable replaceArray(string $search, iterable $replace)

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

Parameters

string $search
iterable $replace

Return Value

Stringable

at line 593
Stringable replaceFirst(string $search, string $replace)

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

Parameters

string $search
string $replace

Return Value

Stringable

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

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

Return Value

Stringable

at line 609
Stringable replaceLast(string $search, string $replace)

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

Parameters

string $search
string $replace

Return Value

Stringable

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

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

Return Value

Stringable

at line 627
Stringable replaceMatches(array|string $pattern, Closure|array|string $replace, int $limit = -1)

Replace the patterns matching the given regular expression.

Parameters

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

Return Value

Stringable

at line 639
Collection scan(string $format)

Parse input from a string to a collection, according to a format.

Parameters

string $format

Return Value

Collection

at line 647
Stringable squish()

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

Return Value

Stringable

at line 655
Stringable start(string $prefix)

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

Parameters

string $prefix

Return Value

Stringable

at line 665
Stringable stripTags(array|string|null $allowedTags = null)

Strip HTML and PHP tags from the given string.

Parameters

array|string|null $allowedTags

Return Value

Stringable

at line 673
Stringable upper()

Convert the given string to upper-case.

Return Value

Stringable

at line 681
Stringable title()

Convert the given string to proper case.

Return Value

Stringable

at line 689
Stringable headline()

Convert the given string to proper case for each word.

Return Value

Stringable

at line 697
Stringable initials(bool $capitalize = false)

Convert the given string to only its initials.

Parameters

bool $capitalize

Return Value

Stringable

at line 705
Stringable apa()

Convert the given string to APA-style title case.

Return Value

Stringable

at line 713
Stringable transliterate(string|null $unknown = '?', bool|null $strict = false)

Transliterate a string to its closest ASCII representation.

Parameters

string|null $unknown
bool|null $strict

Return Value

Stringable

at line 721
Stringable singular()

Get the singular form of an English word.

Return Value

Stringable

at line 731
Stringable slug(string $separator = '-', string|null $language = 'en', array $dictionary = ['@' => 'at'])

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

Parameters

string $separator
string|null $language
array $dictionary

Return Value

Stringable

at line 739
Stringable snake(string $delimiter = '_')

Convert a string to snake case.

Parameters

string $delimiter

Return Value

Stringable

at line 749
bool startsWith(string|int|float|bool|Stringable|iterable|null $needles)

Determine if a given string starts with a given substring.

Parameters

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

Return Value

bool

at line 759
bool doesntStartWith(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|iterable|null $needles

Return Value

bool

at line 767
Stringable studly(bool $normalize = false)

Convert a value to studly caps case.

Parameters

bool $normalize

Return Value

Stringable

at line 775
Stringable pascal(bool $normalize = false)

Convert the string to Pascal case.

Parameters

bool $normalize

Return Value

Stringable

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

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

Parameters

int $start
int|null $length
string $encoding

Return Value

Stringable

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

Returns the number of substring occurrences.

Parameters

string $needle
int $offset
int|null $length

Return Value

int

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

Replace text within a portion of a string.

Parameters

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

Return Value

Stringable

at line 811
Stringable swap(array $map)

Swap multiple keywords in a string with other keywords.

Parameters

array $map

Return Value

Stringable

at line 819
Stringable take(int $limit)

Take the first or last {$limit} characters.

Parameters

int $limit

Return Value

Stringable

at line 831
Stringable trim(string|null $characters = null)

Trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

at line 839
Stringable ltrim(string|null $characters = null)

Left trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

at line 847
Stringable rtrim(string|null $characters = null)

Right trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

at line 855
Stringable lcfirst()

Make a string's first character lowercase.

Return Value

Stringable

at line 863
Stringable ucfirst()

Make a string's first character uppercase.

Return Value

Stringable

at line 871
Stringable ucwords(string $separators = " \t\r\n\f\v")

Capitalize the first character of each word in a string.

Parameters

string $separators

Return Value

Stringable

at line 881
Collection ucsplit()

Split a string by uppercase characters.

Return Value

Collection

at line 891
mixed whenContains(string|iterable $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string contains a given substring.

Parameters

string|iterable $needles
callable $callback
callable|null $default

Return Value

mixed

at line 901
mixed whenContainsAll(iterable $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string contains all array values.

Parameters

iterable $needles
callable $callback
callable|null $default

Return Value

mixed

at line 909
mixed whenEmpty(callable $callback, callable|null $default = null)

Execute the given callback if the string is empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 917
mixed whenNotEmpty(callable $callback, callable|null $default = null)

Execute the given callback if the string is not empty.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 927
mixed whenEndsWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string ends with a given substring.

Parameters

string|int|float|bool|Stringable|iterable|null $needles
callable $callback
callable|null $default

Return Value

mixed

at line 937
mixed whenDoesntEndWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string doesn't end with a given substring.

Parameters

string|int|float|bool|Stringable|iterable|null $needles
callable $callback
callable|null $default

Return Value

mixed

at line 945
mixed whenExactly(string $value, callable $callback, callable|null $default = null)

Execute the given callback if the string is an exact match with the given value.

Parameters

string $value
callable $callback
callable|null $default

Return Value

mixed

at line 953
mixed whenNotExactly(string $value, callable $callback, callable|null $default = null)

Execute the given callback if the string is not an exact match with the given value.

Parameters

string $value
callable $callback
callable|null $default

Return Value

mixed

at line 963
mixed whenIs(string|int|float|bool|Stringable|iterable|null $pattern, callable $callback, callable|null $default = null)

Execute the given callback if the string matches a given pattern.

Parameters

string|int|float|bool|Stringable|iterable|null $pattern
callable $callback
callable|null $default

Return Value

mixed

at line 971
mixed whenIsAscii(callable $callback, callable|null $default = null)

Execute the given callback if the string is 7 bit ASCII.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 979
mixed whenIsUuid(callable $callback, callable|null $default = null)

Execute the given callback if the string is a valid UUID.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 987
mixed whenIsUlid(callable $callback, callable|null $default = null)

Execute the given callback if the string is a valid ULID.

Parameters

callable $callback
callable|null $default

Return Value

mixed

at line 997
mixed whenStartsWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string starts with a given substring.

Parameters

string|int|float|bool|Stringable|iterable|null $needles
callable $callback
callable|null $default

Return Value

mixed

at line 1007
mixed whenDoesntStartWith(string|int|float|bool|Stringable|iterable|null $needles, callable $callback, callable|null $default = null)

Execute the given callback if the string doesn't start with a given substring.

Parameters

string|int|float|bool|Stringable|iterable|null $needles
callable $callback
callable|null $default

Return Value

mixed

at line 1015
mixed whenTest(string $pattern, callable $callback, callable|null $default = null)

Execute the given callback if the string matches the given pattern.

Parameters

string $pattern
callable $callback
callable|null $default

Return Value

mixed

at line 1023
Stringable words(int $words = 100, string $end = '...')

Limit the number of words in a string.

Parameters

int $words
string $end

Return Value

Stringable

at line 1031
int wordCount(string|null $characters = null)

Get the number of words a string contains.

Parameters

string|null $characters

Return Value

int

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

Wrap a string to a given number of characters.

Parameters

int $characters
string $break
bool $cutLongWords

Return Value

Stringable

at line 1047
Stringable wrap(string $before, string|null $after = null)

Wrap the string with the given strings.

Parameters

string $before
string|null $after

Return Value

Stringable

at line 1055
Stringable unwrap(string $before, string|null $after = null)

Unwrap the string with the given strings.

Parameters

string $before
string|null $after

Return Value

Stringable

at line 1063
HtmlString toHtmlString()

Convert the string into a HtmlString instance.

Return Value

HtmlString

at line 1071
Stringable toBase64()

Convert the string to Base64 encoding.

Return Value

Stringable

at line 1079
Stringable fromBase64(bool $strict = false)

Decode the Base64 encoded string.

Parameters

bool $strict

Return Value

Stringable

at line 1087
Stringable hash(string $algorithm)

Hash the string using the given algorithm.

Parameters

string $algorithm

Return Value

Stringable

at line 1095
Stringable encrypt(bool $serialize = false)

Encrypt the string.

Parameters

bool $serialize

Return Value

Stringable

at line 1103
Stringable decrypt(bool $serialize = false)

Decrypt the string.

Parameters

bool $serialize

Return Value

Stringable

at line 1121
string value()

Get the underlying string value.

Return Value

string

at line 1129
string toString()

Get the underlying string value.

Return Value

string

at line 1137
int toInteger(int $base = 10)

Get the underlying string value as an integer.

Parameters

int $base

Return Value

int

at line 1145
float toFloat()

Get the underlying string value as a float.

Return Value

float

at line 1155
bool toBoolean()

Get the underlying string value as a boolean.

Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.

Return Value

bool

at line 1165
CarbonInterface|null toDate(string|null $format = null, string|null $tz = null)

Get the underlying string value as a Carbon instance.

Parameters

string|null $format
string|null $tz

Return Value

CarbonInterface|null

Exceptions

InvalidFormatException

at line 1177
Uri toUri()

Get the underlying string value as a Uri instance.

Return Value

Uri

at line 1185
string jsonSerialize()

Convert the object to a string when JSON encoded.

Return Value

string

at line 1193
bool offsetExists(mixed $offset)

Determine if the given offset exists.

Parameters

mixed $offset

Return Value

bool

at line 1201
string offsetGet(mixed $offset)

Get the value at the given offset.

Parameters

mixed $offset

Return Value

string

at line 1209
void offsetSet(mixed $offset, mixed $value)

Set the value at the given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 1217
void offsetUnset(mixed $offset)

Unset the value at the given offset.

Parameters

mixed $offset

Return Value

void

at line 1225
static void flushState()

Flush all static state.

Return Value

void

at line 1233
mixed __get(string $key)

Proxy dynamic properties onto methods.

Parameters

string $key

Return Value

mixed

at line 1241
string __toString()

Get the raw string value.

Return Value

string