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 (or resolves to) truthy.
Apply the callback if the given "value" is (or resolves to) 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.
Append a new line 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.
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.
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 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 valid JSON.
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.
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.
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.
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 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 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 the string with the given strings.
Convert the string into a HtmlString instance.
Dump the string.
Dump the string and end the script.
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.
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.
        
                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(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.
        
                            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
    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
    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|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
    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 = '...')
        
    
    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
    inlineMarkdown(array $options = [])
        
    
    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.
        
                            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<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.
        
                            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)
        
    
    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
    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
    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 $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', 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
    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
    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
    wrap(string $before, string|null $after = null)
        
    
    Wrap the string with the given strings.
        
                            HtmlString
    toHtmlString()
        
    
    Convert the string into a HtmlString instance.
        
                            $this
    dump()
        
    
    Dump the string.
        
                            never
    dd()
        
    
    Dump the string and end the script.
        
                            string
    value()
        
    
    Get the underlying string value.
        
                            string
    toString()
        
    
    Get the underlying string value.
        
                            int
    toInteger()
        
    
    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.
        
                            mixed
    __get(string $key)
        
    
    Proxy dynamic properties onto methods.
        
                            string
    __toString()
        
    
    Get the raw string value.