Stringable
class Stringable implements JsonSerializable, ArrayAccess, Stringable (View source)
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 the given values to the string.
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.
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.
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.
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 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.
Convert a value to studly caps 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.
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 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 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.
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.
Proxy dynamic properties onto methods.
Get the raw string value.
Details
$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)
Apply the callback if the given "value" is (or resolves to) truthy.
$this|TUnlessReturnType
unless($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.
$this
dump(mixed ...$args)
Dump the string.
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks 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.
tap($callback = null)
Call the given Closure with this instance then return the instance.
void
__construct(string $value = '')
Create a new instance of the class.
Stringable
after(string $search)
Return the remainder of a string after the first occurrence of a given value.
Stringable
afterLast(string $search)
Return the remainder of a string after the last occurrence of a given value.
Stringable
append(array|string ...$values)
Append the given values to the string.
$this
newLine(int $count = 1)
Append a new line to the string.
Stringable
ascii(string $language = 'en')
Transliterate a UTF-8 value to ASCII.
Stringable
basename(string $suffix = '')
Get the trailing name component of the path.
string|false
charAt(int $index)
Get the character at the specified index.
Stringable
chopStart(string|array $needle)
Remove the given string if it exists at the start of the current string.
Stringable
chopEnd(string|array $needle)
Remove the given string if it exists at the end of the current string.
Stringable
classBasename()
Get the basename of the class path.
Stringable
before(string $search)
Get the portion of a string before the first occurrence of a given value.
Stringable
beforeLast(string $search)
Get the portion of a string before the last occurrence of a given value.
Stringable
between(string $from, string $to)
Get the portion of a string between two given values.
Stringable
betweenFirst(string $from, string $to)
Get the smallest possible portion of a string between two given values.
Stringable
camel()
Convert a value to camel case.
bool
contains(string|iterable<string> $needles, bool $ignoreCase = false)
Determine if a given string contains a given substring.
bool
containsAll(iterable<string> $needles, bool $ignoreCase = false)
Determine if a given string contains all array values.
Stringable
convertCase(int $mode = MB_CASE_FOLD, string|null $encoding = 'UTF-8')
Convert the case of a string.
Stringable
deduplicate(string $character = ' ')
Replace consecutive instances of a given character with a single character.
Stringable
dirname(int $levels = 1)
Get the parent directory's path.
bool
endsWith(string|iterable<string> $needles)
Determine if a given string ends with a given substring.
bool
exactly(Stringable|string $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.
Collection<int,string>
explode(string $delimiter, int $limit = PHP_INT_MAX)
Explode the string into a collection.
Collection<int,string>
split(string|int $pattern, int $limit = -1, int $flags = 0)
Split a string using a regular expression or by length.
Stringable
finish(string $cap)
Cap a string with a single instance of a given value.
bool
is(string|iterable<string> $pattern)
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()
Determine if a given value is a valid URL.
bool
isUuid()
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.
Stringable
kebab()
Convert a string to kebab case.
int
length(string|null $encoding = null)
Return the length of the given string.
Stringable
limit(int $limit = 100, string $end = '...', bool $preserveWords = false)
Limit the number of characters in a string.
Stringable
lower()
Convert the given string to lower-case.
Stringable
markdown(array $options = [], array $extensions = [])
Convert GitHub flavored Markdown into HTML.
Stringable
inlineMarkdown(array $options = [], array $extensions = [])
Convert inline Markdown into HTML.
Stringable
mask(string $character, int $index, int|null $length = null, string $encoding = 'UTF-8')
Masks a portion of a string with a repeated character.
Stringable
match(string $pattern)
Get the string matching the given pattern.
bool
isMatch(string|iterable<string> $pattern)
Determine if a given string matches a given pattern.
Collection
matchAll(string $pattern)
Get the string matching the given pattern.
bool
test(string $pattern)
Determine if the string matches the given pattern.
Stringable
numbers()
Remove all non-numeric characters from a string.
Stringable
padBoth(int $length, string $pad = ' ')
Pad both sides of the string with another.
Stringable
padLeft(int $length, string $pad = ' ')
Pad the left side of the string with another.
Stringable
padRight(int $length, string $pad = ' ')
Pad the right side of the string with another.
array<int,string|null>
parseCallback(string|null $default = null)
Parse a Class@method style callback into class and method.
Stringable
pipe(callable $callback)
Call the given callback and return a new string.
Stringable
plural(int|array|Countable $count = 2)
Get the plural form of an English word.
Stringable
pluralStudly(int|array|Countable $count = 2)
Pluralize the last word of an English, studly 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.
Stringable
prepend(string ...$values)
Prepend the given values to the string.
Stringable
remove(string|iterable<string> $search, bool $caseSensitive = true)
Remove any occurrence of the given string in the subject.
Stringable
reverse()
Reverse the string.
Stringable
repeat(int $times)
Repeat the string.
Stringable
replace(string|iterable<string> $search, string|iterable<string> $replace, bool $caseSensitive = true)
Replace the given value in the given string.
Stringable
replaceArray(string $search, iterable<string> $replace)
Replace a given value in the string sequentially with an array.
Stringable
replaceFirst(string $search, string $replace)
Replace the first occurrence of a given value in the string.
Stringable
replaceStart(string $search, string $replace)
Replace the first occurrence of the given value if it appears at the start of the string.
Stringable
replaceLast(string $search, string $replace)
Replace the last occurrence of a given value in the string.
Stringable
replaceEnd(string $search, string $replace)
Replace the last occurrence of a given value if it appears at the end of the string.
Stringable
replaceMatches(array|string $pattern, Closure|string[]|string $replace, int $limit = -1)
Replace the patterns matching the given regular expression.
Collection
scan(string $format)
Parse input from a string to a collection, according to a format.
Stringable
squish()
Remove all "extra" blank space from the given string.
Stringable
start(string $prefix)
Begin a string with a single instance of a given value.
Stringable
stripTags(string[]|string|null $allowedTags = null)
Strip HTML and PHP tags from the given string.
Stringable
upper()
Convert the given string to upper-case.
Stringable
title()
Convert the given string to proper case.
Stringable
headline()
Convert the given string to proper case for each word.
Stringable
apa()
Convert the given string to APA-style title case.
Stringable
transliterate(string|null $unknown = '?', bool|null $strict = false)
Transliterate a string to its closest ASCII representation.
Stringable
singular()
Get the singular form of an English word.
Stringable
slug(string $separator = '-', string|null $language = 'en', array<string,string> $dictionary = ['@' => 'at'])
Generate a URL friendly "slug" from a given string.
Stringable
snake(string $delimiter = '_')
Convert a string to snake case.
bool
startsWith(string|iterable<string> $needles)
Determine if a given string starts with a given substring.
Stringable
studly()
Convert a value to studly caps case.
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.
int
substrCount(string $needle, int $offset = 0, int|null $length = null)
Returns the number of substring occurrences.
Stringable
substrReplace(string|string[] $replace, int|int[] $offset = 0, int|int[]|null $length = null)
Replace text within a portion of a string.
Stringable
swap(array $map)
Swap multiple keywords in a string with other keywords.
Stringable
take(int $limit)
Take the first or last {$limit} characters.
Stringable
trim(string $characters = null)
Trim the string of the given characters.
Stringable
ltrim(string $characters = null)
Left trim the string of the given characters.
Stringable
rtrim(string $characters = null)
Right trim the string of the given characters.
Stringable
lcfirst()
Make a string's first character lowercase.
Stringable
ucfirst()
Make a string's first character uppercase.
Collection<int,string>
ucsplit()
Split a string by uppercase characters.
Stringable
whenContains(string|iterable<string> $needles, callable $callback, callable|null $default = null)
Execute the given callback if the string contains a given substring.
Stringable
whenContainsAll(array $needles, callable $callback, callable|null $default = null)
Execute the given callback if the string contains all array values.
Stringable
whenEmpty(callable $callback, callable|null $default = null)
Execute the given callback if the string is empty.
Stringable
whenNotEmpty(callable $callback, callable|null $default = null)
Execute the given callback if the string is not empty.
Stringable
whenEndsWith(string|iterable<string> $needles, callable $callback, callable|null $default = null)
Execute the given callback if the string ends with a given substring.
Stringable
whenExactly(string $value, callable $callback, callable|null $default = null)
Execute the given callback if the string is an exact match with the given value.
Stringable
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.
Stringable
whenIs(string|iterable<string> $pattern, callable $callback, callable|null $default = null)
Execute the given callback if the string matches a given pattern.
Stringable
whenIsAscii(callable $callback, callable|null $default = null)
Execute the given callback if the string is 7 bit ASCII.
Stringable
whenIsUuid(callable $callback, callable|null $default = null)
Execute the given callback if the string is a valid UUID.
Stringable
whenIsUlid(callable $callback, callable|null $default = null)
Execute the given callback if the string is a valid ULID.
Stringable
whenStartsWith(string|iterable<string> $needles, callable $callback, callable|null $default = null)
Execute the given callback if the string starts with a given substring.
Stringable
whenTest(string $pattern, callable $callback, callable|null $default = null)
Execute the given callback if the string matches the given pattern.
Stringable
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.
Stringable
wordWrap(int $characters = 75, string $break = "\n", bool $cutLongWords = false)
Wrap a string to a given number of characters.
Stringable
wrap(string $before, string|null $after = null)
Wrap the string with the given strings.
Stringable
unwrap(string $before, string|null $after = null)
Unwrap the string with the given strings.
HtmlString
toHtmlString()
Convert the string into a HtmlString
instance.
Stringable
toBase64()
Convert the string to Base64 encoding.
Stringable
fromBase64(bool $strict = false)
Decode the Base64 encoded 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.
Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
Carbon
toDate(string|null $format = null, string|null $tz = null)
Get the underlying string value as a Carbon 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.
mixed
__get(string $key)
Proxy dynamic properties onto methods.
string
__toString()
Get the raw string value.