class Stringable implements JsonSerializable, ArrayAccess, Stringable, Transient

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(int $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(array|string $characters = ' ')

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 = [])

Extract 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')

Mask 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 $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')

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

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

Return 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 1123
Stringable dump(mixed ...$args)

Dump the string.

Parameters

mixed ...$args

Return Value

Stringable

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

Register a custom macro.

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 44
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

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 61
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

in Macroable at line 72
static void flushMacros()

Flush the existing macros.

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

Return Value

void

in Macroable at line 83
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 108
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 17
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 36
__construct(mixed $value = '')

Create a new instance of the class.

Parameters

mixed $value

at line 44
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 52
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 60
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 68
Stringable newLine(int $count = 1)

Append a new line to the string.

Parameters

int $count

Return Value

Stringable

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

Transliterate a UTF-8 value to ASCII.

Parameters

string $language

Return Value

Stringable

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

Get the trailing name component of the path.

Parameters

string $suffix

Return Value

Stringable

at line 92
string|false charAt(int $index)

Get the character at the specified index.

Parameters

int $index

Return Value

string|false

at line 100
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 108
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 116
Stringable classBasename()

Get the basename of the class path.

Return Value

Stringable

at line 124
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 132
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 140
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 148
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 156
Stringable camel()

Convert a value to camel case.

Return Value

Stringable

at line 166
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 176
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 186
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 196
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 204
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 214
Stringable deduplicate(array|string $characters = ' ')

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

Parameters

array|string $characters

Return Value

Stringable

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

Get the parent directory's path.

Parameters

int $levels

Return Value

Stringable

at line 232
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 242
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 250
bool exactly(mixed $value)

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

Parameters

mixed $value

Return Value

bool

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

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

Parameters

string $phrase
array $options

Return Value

string|null

at line 274
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 286
Collection split(string|int $pattern, int $limit = -1, int $flags = 0)

Split a string using a regular expression or by length.

PREG_SPLIT_OFFSET_CAPTURE makes a pattern split return [segment, offset] pairs; a length split ignores flags.

Parameters

string|int $pattern
int $limit
int $flags

Return Value

Collection

at line 300
Stringable finish(string $cap)

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

Parameters

string $cap

Return Value

Stringable

at line 310
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 318
bool isAscii()

Determine if a given string is 7 bit ASCII.

Return Value

bool

at line 326
bool isJson()

Determine if a given string is valid JSON.

Return Value

bool

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

Determine if a given value is a valid URL.

Parameters

array $protocols

Return Value

bool

at line 344
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 352
bool isUlid()

Determine if a given string is a valid ULID.

Return Value

bool

at line 360
bool isEmpty()

Determine if the given string is empty.

Return Value

bool

at line 368
bool isNotEmpty()

Determine if the given string is not empty.

Return Value

bool

at line 376
Stringable kebab()

Convert a string to kebab case.

Return Value

Stringable

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

Return the length of the given string.

Parameters

string|null $encoding

Return Value

int

at line 392
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 400
Stringable lower()

Convert the given string to lower-case.

Return Value

Stringable

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

Convert GitHub flavored Markdown into HTML.

Parameters

array $options
array $extensions

Return Value

Stringable

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

Convert inline Markdown into HTML.

Parameters

array $options
array $extensions

Return Value

Stringable

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

Mask a portion of a string with a repeated character.

Parameters

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

Return Value

Stringable

at line 432
Stringable match(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Stringable

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

Determine if a given string matches a given pattern.

Parameters

string|iterable $pattern

Return Value

bool

at line 450
Collection matchAll(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Collection

at line 458
bool test(string $pattern)

Determine if the string matches the given pattern.

Parameters

string $pattern

Return Value

bool

at line 466
Stringable numbers()

Remove all non-numeric characters from a string.

Return Value

Stringable

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

Pad both sides of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

at line 482
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 490
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 500
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 508
Stringable pipe(callable $callback)

Call the given callback and return a new string.

Parameters

callable $callback

Return Value

Stringable

at line 516
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 524
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 532
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 540
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 548
Stringable prepend(string ...$values)

Prepend the given values to the string.

Parameters

string ...$values

Return Value

Stringable

at line 558
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 566
Stringable reverse()

Reverse the string.

Return Value

Stringable

at line 574
Stringable repeat(int $times)

Repeat the string.

Parameters

int $times

Return Value

Stringable

at line 585
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 595
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 603
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 611
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 619
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 627
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 637
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 649
Collection scan(string $format)

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

Parameters

string $format

Return Value

Collection

at line 657
Stringable squish()

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

Return Value

Stringable

at line 665
Stringable start(string $prefix)

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

Parameters

string $prefix

Return Value

Stringable

at line 675
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 683
Stringable upper()

Convert the given string to upper-case.

Return Value

Stringable

at line 691
Stringable title()

Convert the given string to proper case.

Return Value

Stringable

at line 699
Stringable headline()

Convert the given string to proper case for each word.

Return Value

Stringable

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

Convert the given string to only its initials.

Parameters

bool $capitalize

Return Value

Stringable

at line 715
Stringable apa()

Convert the given string to APA-style title case.

Return Value

Stringable

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

Transliterate a string to its closest ASCII representation.

Parameters

string|null $unknown
bool $strict

Return Value

Stringable

at line 731
Stringable singular()

Get the singular form of an English word.

Return Value

Stringable

at line 741
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 749
Stringable snake(string $delimiter = '_')

Convert a string to snake case.

Parameters

string $delimiter

Return Value

Stringable

at line 759
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 769
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 777
Stringable studly(bool $normalize = false)

Convert a value to studly caps case.

Parameters

bool $normalize

Return Value

Stringable

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

Convert the string to Pascal case.

Parameters

bool $normalize

Return Value

Stringable

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

Return 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 801
int substrCount(string $needle, int $offset = 0, int|null $length = null)

Return the number of substring occurrences.

Parameters

string $needle
int $offset
int|null $length

Return Value

int

at line 813
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 821
Stringable swap(array $map)

Swap multiple keywords in a string with other keywords.

Parameters

array $map

Return Value

Stringable

at line 829
Stringable take(int $limit)

Take the first or last {$limit} characters.

Parameters

int $limit

Return Value

Stringable

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

Trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

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

Left trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

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

Right trim the string of the given characters.

Parameters

string|null $characters

Return Value

Stringable

at line 865
Stringable lcfirst()

Make a string's first character lowercase.

Return Value

Stringable

at line 873
Stringable ucfirst()

Make a string's first character uppercase.

Return Value

Stringable

at line 881
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 891
Collection ucsplit()

Split a string by uppercase characters.

Return Value

Collection

at line 901
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 911
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 919
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 927
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 937
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 947
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 955
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 963
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 973
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 981
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 989
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 997
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 1007
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 1017
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 1025
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 1033
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 1041
int wordCount(string|null $characters = null)

Get the number of words a string contains.

Parameters

string|null $characters

Return Value

int

at line 1049
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 1057
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 1065
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 1073
HtmlString toHtmlString()

Convert the string into a HtmlString instance.

Return Value

HtmlString

at line 1081
Stringable toBase64()

Convert the string to Base64 encoding.

Return Value

Stringable

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

Decode the Base64 encoded string.

Parameters

bool $strict

Return Value

Stringable

at line 1097
Stringable hash(string $algorithm)

Hash the string using the given algorithm.

Parameters

string $algorithm

Return Value

Stringable

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

Encrypt the string.

Parameters

bool $serialize

Return Value

Stringable

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

Decrypt the string.

Parameters

bool $serialize

Return Value

Stringable

at line 1133
string value()

Get the underlying string value.

Return Value

string

at line 1141
string toString()

Get the underlying string value.

Return Value

string

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

Get the underlying string value as an integer.

Parameters

int $base

Return Value

int

at line 1157
float toFloat()

Get the underlying string value as a float.

Return Value

float

at line 1167
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 1177
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 1189
Uri toUri()

Get the underlying string value as a Uri instance.

Return Value

Uri

at line 1197
string jsonSerialize()

Convert the object to a string when JSON encoded.

Return Value

string

at line 1205
bool offsetExists(mixed $offset)

Determine if the given offset exists.

Parameters

mixed $offset

Return Value

bool

at line 1213
string offsetGet(mixed $offset)

Get the value at the given offset.

Parameters

mixed $offset

Return Value

string

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

Set the value at the given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

at line 1229
void offsetUnset(mixed $offset)

Unset the value at the given offset.

Parameters

mixed $offset

Return Value

void

at line 1237
static void flushState()

Flush all static state.

Return Value

void

at line 1245
mixed __get(string $key)

Proxy dynamic properties onto methods.

Parameters

string $key

Return Value

mixed

at line 1253
string __toString()

Get the raw string value.

Return Value

string