Stringable
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
Apply the callback if the given "value" is (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) falsy.
Dump the string.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Call the given Closure with this instance then return the instance.
Create a new instance of the class.
Return the remainder of a string after the first occurrence of a given value.
Return the remainder of a string after the last occurrence of a given value.
Append a new line to the string.
Transliterate a UTF-8 value to ASCII.
Get the trailing name component of the path.
Get the character at the specified index.
Remove the given string if it exists at the start of the current string.
Remove the given string if it exists at the end of the current string.
Get the basename of the class path.
Get the portion of a string before the first occurrence of a given value.
Get the portion of a string before the last occurrence of a given value.
Get the portion of a string between two given values.
Get the smallest possible portion of a string between two given values.
Convert a value to camel case.
Determine if a given string contains a given substring.
Determine if a given string contains all array values.
Determine if a given string doesn't contain a given substring.
Convert the case of a string.
Replace consecutive instances of a given character with a single character.
Get the parent directory's path.
Determine if a given string ends with a given substring.
Determine if a given string doesn't end with a given substring.
Determine if the string is an exact match with the given value.
Extracts an excerpt from text that matches the first instance of a phrase.
Explode the string into a collection.
Split a string using a regular expression or by length.
Cap a string with a single instance of a given value.
Determine if a given string matches a given pattern.
Determine if a given string is 7 bit ASCII.
Determine if a given string is valid JSON.
Determine if a given value is a valid URL.
Determine if a given string is a valid UUID.
Determine if a given string is a valid ULID.
Determine if the given string is empty.
Determine if the given string is not empty.
Convert a string to kebab case.
Return the length of the given string.
Limit the number of characters in a string.
Convert the given string to lower-case.
Convert GitHub flavored Markdown into HTML.
Convert inline Markdown into HTML.
Masks a portion of a string with a repeated character.
Get the string matching the given pattern.
Determine if a given string matches a given pattern.
Get the string matching the given pattern.
Determine if the string matches the given pattern.
Remove all non-numeric characters from a string.
Pad both sides of the string with another.
Pad the left side of the string with another.
Pad the right side of the string with another.
Parse a Class@method style callback into class and method.
Call the given callback and return a new string.
Pluralize the last word of an English, studly caps case string.
Pluralize the last word of an English, Pascal caps case string.
Find the multi-byte safe position of the first occurrence of the given substring.
Prepend the given values to the string.
Remove any occurrence of the given string in the subject.
Reverse the string.
Repeat the string.
Replace the given value in the given string.
Replace a given value in the string sequentially with an array.
Replace the first occurrence of a given value in the string.
Replace the first occurrence of the given value if it appears at the start of the string.
Replace the last occurrence of a given value in the string.
Replace the last occurrence of a given value if it appears at the end of the string.
Replace the patterns matching the given regular expression.
Parse input from a string to a collection, according to a format.
Remove all "extra" blank space from the given string.
Begin a string with a single instance of a given value.
Strip HTML and PHP tags from the given string.
Convert the given string to upper-case.
Convert the given string to proper case.
Convert the given string to proper case for each word.
Convert the given string to only its initials.
Convert the given string to APA-style title case.
Transliterate a string to its closest ASCII representation.
Get the singular form of an English word.
Generate a URL friendly "slug" from a given string.
Convert a string to snake case.
Determine if a given string starts with a given substring.
Determine if a given string doesn't start with a given substring.
Convert a value to studly caps case.
Convert the string to Pascal case.
Returns the portion of the string specified by the start and length parameters.
Returns the number of substring occurrences.
Replace text within a portion of a string.
Swap multiple keywords in a string with other keywords.
Take the first or last {$limit} characters.
Trim the string of the given characters.
Left trim the string of the given characters.
Right trim the string of the given characters.
Make a string's first character lowercase.
Make a string's first character uppercase.
Capitalize the first character of each word in a string.
Split a string by uppercase characters.
Execute the given callback if the string contains a given substring.
Execute the given callback if the string contains all array values.
Execute the given callback if the string is empty.
Execute the given callback if the string is not empty.
Execute the given callback if the string ends with a given substring.
Execute the given callback if the string doesn't end with a given substring.
Execute the given callback if the string is an exact match with the given value.
Execute the given callback if the string is not an exact match with the given value.
Execute the given callback if the string matches a given pattern.
Execute the given callback if the string is 7 bit ASCII.
Execute the given callback if the string is a valid UUID.
Execute the given callback if the string is a valid ULID.
Execute the given callback if the string starts with a given substring.
Execute the given callback if the string doesn't start with a given substring.
Execute the given callback if the string matches the given pattern.
Limit the number of words in a string.
Get the number of words a string contains.
Wrap a string to a given number of characters.
Wrap the string with the given strings.
Unwrap the string with the given strings.
Convert the string into a HtmlString instance.
Convert the string to Base64 encoding.
Decode the Base64 encoded string.
Hash the string using the given algorithm.
Encrypt the string.
Decrypt the string.
Get the underlying string value.
Get the underlying string value.
Get the underlying string value as an integer.
Get the underlying string value as a float.
Get the underlying string value as a boolean.
Get the underlying string value as a Carbon instance.
Convert the object to a string when JSON encoded.
Determine if the given offset exists.
Get the value at the given offset.
Set the value at the given offset.
Unset the value at the given offset.
Flush all static state.
Proxy dynamic properties onto methods.
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.
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.
in
Dumpable at line 12
never
dd(mixed ...$args)
Dump the given arguments and terminate execution.
at line 1111
Stringable
dump(mixed ...$args)
Dump the string.
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.
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.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
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.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
in
Tappable at line 15
mixed
tap(callable|null $callback = null)
Call the given Closure with this instance then return the instance.
at line 34
__construct(mixed $value = '')
Create a new instance of the class.
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.
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.
at line 58
Stringable
append(string|int|float|bool|Stringable|null ...$values)
Append the given values to the string.
at line 66
Stringable
newLine(int $count = 1)
Append a new line to the string.
at line 74
Stringable
ascii(string $language = 'en')
Transliterate a UTF-8 value to ASCII.
at line 82
Stringable
basename(string $suffix = '')
Get the trailing name component of the path.
at line 90
string|false
charAt(mixed $index)
Get the character at the specified index.
at line 98
Stringable
chopStart(string|array $needle)
Remove the given string if it exists at the start of the current string.
at line 106
Stringable
chopEnd(string|array $needle)
Remove the given string if it exists at the end of the current string.
at line 114
Stringable
classBasename()
Get the basename of the class path.
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.
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.
at line 138
Stringable
between(string $from, string $to)
Get the portion of a string between two given values.
at line 146
Stringable
betweenFirst(string $from, string $to)
Get the smallest possible portion of a string between two given values.
at line 154
Stringable
camel()
Convert a value to camel case.
at line 164
bool
contains(string|iterable $needles, bool $ignoreCase = false)
Determine if a given string contains a given substring.
at line 174
bool
containsAll(iterable $needles, bool $ignoreCase = false)
Determine if a given string contains all array values.
at line 184
bool
doesntContain(string|iterable $needles, bool $ignoreCase = false)
Determine if a given string doesn't contain a given substring.
at line 192
Stringable
convertCase(int $mode = MB_CASE_FOLD, string|null $encoding = 'UTF-8')
Convert the case of a string.
at line 200
Stringable
counted(int|array|Countable $count)
Get the plural form of an English word with the count prepended.
at line 208
Stringable
deduplicate(string $character = ' ')
Replace consecutive instances of a given character with a single character.
at line 216
Stringable
dirname(int $levels = 1)
Get the parent directory's path.
at line 226
bool
endsWith(string|int|float|bool|Stringable|iterable|null $needles)
Determine if a given string ends with a given substring.
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.
at line 244
bool
exactly(mixed $value)
Determine if the string is an exact match with the given value.
at line 256
string|null
excerpt(string $phrase = '', array $options = [])
Extracts an excerpt from text that matches the first instance of a phrase.
at line 266
Collection
explode(string $delimiter, int $limit = PHP_INT_MAX)
Explode the string into a 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.
at line 290
Stringable
finish(string $cap)
Cap a string with a single instance of a given value.
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.
at line 308
bool
isAscii()
Determine if a given string is 7 bit ASCII.
at line 316
bool
isJson()
Determine if a given string is valid JSON.
at line 324
bool
isUrl(array $protocols = [])
Determine if a given value is a valid URL.
at line 334
bool
isUuid(int|string|null $version = null)
Determine if a given string is a valid UUID.
at line 342
bool
isUlid()
Determine if a given string is a valid ULID.
at line 350
bool
isEmpty()
Determine if the given string is empty.
at line 358
bool
isNotEmpty()
Determine if the given string is not empty.
at line 366
Stringable
kebab()
Convert a string to kebab case.
at line 374
int
length(string|null $encoding = null)
Return the length of the given string.
at line 382
Stringable
limit(int $limit = 100, string $end = '...', bool $preserveWords = false)
Limit the number of characters in a string.
at line 390
Stringable
lower()
Convert the given string to lower-case.
at line 398
Stringable
markdown(array $options = [], array $extensions = [])
Convert GitHub flavored Markdown into HTML.
at line 406
Stringable
inlineMarkdown(array $options = [], array $extensions = [])
Convert inline Markdown into HTML.
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.
at line 422
Stringable
match(string $pattern)
Get the string matching the given pattern.
at line 432
bool
isMatch(string|iterable $pattern)
Determine if a given string matches a given pattern.
at line 440
Collection
matchAll(string $pattern)
Get the string matching the given pattern.
at line 448
bool
test(string $pattern)
Determine if the string matches the given pattern.
at line 456
Stringable
numbers()
Remove all non-numeric characters from a string.
at line 464
Stringable
padBoth(int $length, string $pad = ' ')
Pad both sides of the string with another.
at line 472
Stringable
padLeft(int $length, string $pad = ' ')
Pad the left side of the string with another.
at line 480
Stringable
padRight(int $length, string $pad = ' ')
Pad the right side of the string with another.
at line 490
array
parseCallback(string|null $default = null)
Parse a Class@method style callback into class and method.
at line 498
Stringable
pipe(callable $callback)
Call the given callback and return a new string.
at line 506
Stringable
plural(int|array|Countable $count = 2, bool $prependCount = false)
Get the plural form of an English word.
at line 514
Stringable
pluralStudly(int|array|Countable $count = 2)
Pluralize the last word of an English, studly caps case string.
at line 522
Stringable
pluralPascal(int|array|Countable $count = 2)
Pluralize the last word of an English, Pascal caps case string.
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.
at line 538
Stringable
prepend(string ...$values)
Prepend the given values to the string.
at line 548
Stringable
remove(string|iterable $search, bool $caseSensitive = true)
Remove any occurrence of the given string in the subject.
at line 556
Stringable
reverse()
Reverse the string.
at line 564
Stringable
repeat(int $times)
Repeat the string.
at line 575
Stringable
replace(string|iterable $search, string|iterable $replace, bool $caseSensitive = true)
Replace the given value in the given string.
at line 585
Stringable
replaceArray(string $search, iterable $replace)
Replace a given value in the string sequentially with an array.
at line 593
Stringable
replaceFirst(string $search, string $replace)
Replace the first occurrence of a given value in the string.
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.
at line 609
Stringable
replaceLast(string $search, string $replace)
Replace the last occurrence of a given value in the string.
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.
at line 627
Stringable
replaceMatches(array|string $pattern, Closure|array|string $replace, int $limit = -1)
Replace the patterns matching the given regular expression.
at line 639
Collection
scan(string $format)
Parse input from a string to a collection, according to a format.
at line 647
Stringable
squish()
Remove all "extra" blank space from the given string.
at line 655
Stringable
start(string $prefix)
Begin a string with a single instance of a given value.
at line 665
Stringable
stripTags(array|string|null $allowedTags = null)
Strip HTML and PHP tags from the given string.
at line 673
Stringable
upper()
Convert the given string to upper-case.
at line 681
Stringable
title()
Convert the given string to proper case.
at line 689
Stringable
headline()
Convert the given string to proper case for each word.
at line 697
Stringable
initials(bool $capitalize = false)
Convert the given string to only its initials.
at line 705
Stringable
apa()
Convert the given string to APA-style title case.
at line 713
Stringable
transliterate(string|null $unknown = '?', bool|null $strict = false)
Transliterate a string to its closest ASCII representation.
at line 721
Stringable
singular()
Get the singular form of an English word.
at line 731
Stringable
slug(string $separator = '-', string|null $language = 'en', array $dictionary = ['@' => 'at'])
Generate a URL friendly "slug" from a given string.
at line 739
Stringable
snake(string $delimiter = '_')
Convert a string to snake case.
at line 749
bool
startsWith(string|int|float|bool|Stringable|iterable|null $needles)
Determine if a given string starts with a given substring.
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.
at line 767
Stringable
studly(bool $normalize = false)
Convert a value to studly caps case.
at line 775
Stringable
pascal(bool $normalize = false)
Convert the string to Pascal case.
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.
at line 791
int
substrCount(string $needle, int $offset = 0, int|null $length = null)
Returns the number of substring occurrences.
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.
at line 811
Stringable
swap(array $map)
Swap multiple keywords in a string with other keywords.
at line 819
Stringable
take(int $limit)
Take the first or last {$limit} characters.
at line 831
Stringable
trim(string|null $characters = null)
Trim the string of the given characters.
at line 839
Stringable
ltrim(string|null $characters = null)
Left trim the string of the given characters.
at line 847
Stringable
rtrim(string|null $characters = null)
Right trim the string of the given characters.
at line 855
Stringable
lcfirst()
Make a string's first character lowercase.
at line 863
Stringable
ucfirst()
Make a string's first character uppercase.
at line 871
Stringable
ucwords(string $separators = " \t\r\n\f\v")
Capitalize the first character of each word in a string.
at line 881
Collection
ucsplit()
Split a string by uppercase characters.
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.
at line 901
mixed
whenContainsAll(iterable $needles, callable $callback, callable|null $default = null)
Execute the given callback if the string contains all array values.
at line 909
mixed
whenEmpty(callable $callback, callable|null $default = null)
Execute the given callback if the string is empty.
at line 917
mixed
whenNotEmpty(callable $callback, callable|null $default = null)
Execute the given callback if the string is not empty.
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.
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.
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.
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.
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.
at line 971
mixed
whenIsAscii(callable $callback, callable|null $default = null)
Execute the given callback if the string is 7 bit ASCII.
at line 979
mixed
whenIsUuid(callable $callback, callable|null $default = null)
Execute the given callback if the string is a valid UUID.
at line 987
mixed
whenIsUlid(callable $callback, callable|null $default = null)
Execute the given callback if the string is a valid ULID.
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.
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.
at line 1015
mixed
whenTest(string $pattern, callable $callback, callable|null $default = null)
Execute the given callback if the string matches the given pattern.
at line 1023
Stringable
words(int $words = 100, string $end = '...')
Limit the number of words in a string.
at line 1031
int
wordCount(string|null $characters = null)
Get the number of words a string contains.
at line 1039
Stringable
wordWrap(int $characters = 75, string $break = "\n", bool $cutLongWords = false)
Wrap a string to a given number of characters.
at line 1047
Stringable
wrap(string $before, string|null $after = null)
Wrap the string with the given strings.
at line 1055
Stringable
unwrap(string $before, string|null $after = null)
Unwrap the string with the given strings.
at line 1063
HtmlString
toHtmlString()
Convert the string into a HtmlString instance.
at line 1071
Stringable
toBase64()
Convert the string to Base64 encoding.
at line 1079
Stringable
fromBase64(bool $strict = false)
Decode the Base64 encoded string.
at line 1087
Stringable
hash(string $algorithm)
Hash the string using the given algorithm.
at line 1095
Stringable
encrypt(bool $serialize = false)
Encrypt the string.
at line 1103
Stringable
decrypt(bool $serialize = false)
Decrypt the string.
at line 1121
string
value()
Get the underlying string value.
at line 1129
string
toString()
Get the underlying string value.
at line 1137
int
toInteger(int $base = 10)
Get the underlying string value as an integer.
at line 1145
float
toFloat()
Get the underlying string value as a 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.
at line 1165
CarbonInterface|null
toDate(string|null $format = null, string|null $tz = null)
Get the underlying string value as a Carbon instance.
at line 1177
Uri
toUri()
Get the underlying string value as a Uri instance.
at line 1185
string
jsonSerialize()
Convert the object to a string when JSON encoded.
at line 1193
bool
offsetExists(mixed $offset)
Determine if the given offset exists.
at line 1201
string
offsetGet(mixed $offset)
Get the value at the given offset.
at line 1209
void
offsetSet(mixed $offset, mixed $value)
Set the value at the given offset.
at line 1217
void
offsetUnset(mixed $offset)
Unset the value at the given offset.
at line 1225
static void
flushState()
Flush all static state.
at line 1233
mixed
__get(string $key)
Proxy dynamic properties onto methods.
at line 1241
string
__toString()
Get the raw string value.