Stringable
class Stringable implements JsonSerializable (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 truthy.
Apply the callback if the given "value" is falsy.
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.
Transliterate a UTF-8 value to ASCII.
Get the trailing name component of the path.
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.
Convert a value to camel case.
Determine if a given string contains a given substring.
Determine if a given string contains all array values.
Get the parent directory's path.
Determine if a given string ends with a given substring.
Determine if the string is an exact match with the given value.
Explode the string into an array.
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 a valid UUID.
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.
Masks a portion of a string with a repeated character.
Get the string matching the given pattern.
Get the string matching the given pattern.
Determine if the string matches the given pattern.
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.
Get the plural form of an English word.
Pluralize the last word of an English, studly caps case string.
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 last occurrence of a given value in the string.
Replace the patterns matching the given regular expression.
Parse input from a string to a collection, according to a format.
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 title case.
Convert the given string to title case for each word.
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.
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 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 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 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.
Convert the string into a HtmlString
instance.
Dump the string.
Dump the string and end the script.
Convert the object to a string when JSON encoded.
Proxy dynamic properties onto methods.
Get the raw string value.
Details
$this|mixed
when(mixed $value, callable $callback, callable|null $default = null)
Apply the callback if the given "value" is truthy.
$this|mixed
unless(mixed $value, callable $callback, callable|null $default = null)
Apply the callback if the given "value" is falsy.
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.
$this|HigherOrderTapProxy
tap(callable|null $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 ...$values)
Append the given values 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.
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
camel()
Convert a value to camel case.
bool
contains(string|array $needles)
Determine if a given string contains a given substring.
bool
containsAll(array $needles)
Determine if a given string contains all array values.
Stringable
dirname(int $levels = 1)
Get the parent directory's path.
bool
endsWith(string|array $needles)
Determine if a given string ends with a given substring.
bool
exactly(string $value)
Determine if the string is an exact match with the given value.
Collection
explode(string $delimiter, int $limit = PHP_INT_MAX)
Explode the string into an array.
Collection
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|array $pattern)
Determine if a given string matches a given pattern.
bool
isAscii()
Determine if a given string is 7 bit ASCII.
bool
isUuid()
Determine if a given string is a valid UUID.
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 $encoding = null)
Return the length of the given string.
Stringable
limit(int $limit = 100, string $end = '...')
Limit the number of characters in a string.
Stringable
lower()
Convert the given string to lower-case.
Stringable
markdown(array $options = [])
Convert GitHub flavored 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.
Collection
matchAll(string $pattern)
Get the string matching the given pattern.
bool
test(string $pattern)
Determine if the string matches the given pattern.
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
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 $count = 2)
Get the plural form of an English word.
Stringable
pluralStudly(int $count = 2)
Pluralize the last word of an English, studly caps case string.
Stringable
prepend(array ...$values)
Prepend the given values to the string.
Stringable
remove(string|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|string[] $search, string|string[] $replace)
Replace the given value in the given string.
Stringable
replaceArray(string $search, array $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
replaceLast(string $search, string $replace)
Replace the last occurrence of a given value in the string.
Stringable
replaceMatches(string $pattern, Closure|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
start(string $prefix)
Begin a string with a single instance of a given value.
Stringable
stripTags(string $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 title case.
Stringable
headline()
Convert the given string to title case for each word.
Stringable
singular()
Get the singular form of an English word.
Stringable
slug(string $separator = '-', string|null $language = 'en')
Generate a URL friendly "slug" from a given string.
Stringable
snake(string $delimiter = '_')
Convert a string to snake case.
bool
startsWith(string|array $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)
Returns the portion of the string specified by the start and length parameters.
int
substrCount(string $needle, int|null $offset = null, int|null $length = null)
Returns the number of substring occurrences.
Stringable
substrReplace(string|array $replace, array|int $offset = 0, array|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
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
ucfirst()
Make a string's first character uppercase.
Collection
ucsplit()
Split a string by uppercase characters.
Stringable
whenContains(string|array $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|array $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
whenIs(string|array $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
whenStartsWith(string|array $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()
Get the number of words a string contains.
HtmlString
toHtmlString()
Convert the string into a HtmlString
instance.
$this
dump()
Dump the string.
never
dd()
Dump the string and end the script.
string
jsonSerialize()
Convert the object to a string when JSON encoded.
mixed
__get(string $key)
Proxy dynamic properties onto methods.
string
__toString()
Get the raw string value.