W3cubDocs

/Laravel 8

Stringable

class Stringable (View source)

Traits

Macroable

Properties

static protected array $macros The registered string macros. from Macroable
protected string $value The underlying string value.

Methods

static void macro(string $name, object|callable $macro)

Register a custom macro.

from Macroable
static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

from Macroable
static bool hasMacro(string $name)

Checks if macro is registered.

from Macroable
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

from Macroable
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 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|null match(string $pattern)

Get the string matching the given pattern.

Collection matchAll(string $pattern)

Get the string matching 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 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 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.

Stringable start(string $prefix)

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

Stringable upper()

Convert the given string to upper-case.

Stringable title()

Convert the given string to title case.

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 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 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.

mixed|$this when(mixed $value, callable $callback, callable|null $default = null)

Apply the callback's string changes if the given "value" is true.

Stringable whenEmpty(callable $callback)

Execute the given callback if the string is empty.

Stringable words(int $words = 100, string $end = '...')

Limit the number of words in a string.

$this dump()

Dump the string.

void dd()

Dump the string and end the script.

mixed __get(string $key)

Proxy dynamic properties onto methods.

string __toString()

Get the raw string value.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

void __construct(string $value = '')

Create a new instance of the class.

Parameters

string $value

Return Value

void

Stringable after(string $search)

Return the remainder of a string after the first occurrence of a given value.

Parameters

string $search

Return Value

Stringable

Stringable afterLast(string $search)

Return the remainder of a string after the last occurrence of a given value.

Parameters

string $search

Return Value

Stringable

Stringable append(array ...$values)

Append the given values to the string.

Parameters

array ...$values

Return Value

Stringable

Stringable ascii(string $language = 'en')

Transliterate a UTF-8 value to ASCII.

Parameters

string $language

Return Value

Stringable

Stringable basename(string $suffix = '')

Get the trailing name component of the path.

Parameters

string $suffix

Return Value

Stringable

Stringable classBasename()

Get the basename of the class path.

Return Value

Stringable

Stringable before(string $search)

Get the portion of a string before the first occurrence of a given value.

Parameters

string $search

Return Value

Stringable

Stringable beforeLast(string $search)

Get the portion of a string before the last occurrence of a given value.

Parameters

string $search

Return Value

Stringable

Stringable between(string $from, string $to)

Get the portion of a string between two given values.

Parameters

string $from
string $to

Return Value

Stringable

Stringable camel()

Convert a value to camel case.

Return Value

Stringable

bool contains(string|array $needles)

Determine if a given string contains a given substring.

Parameters

string|array $needles

Return Value

bool

bool containsAll(array $needles)

Determine if a given string contains all array values.

Parameters

array $needles

Return Value

bool

Stringable dirname(int $levels = 1)

Get the parent directory's path.

Parameters

int $levels

Return Value

Stringable

bool endsWith(string|array $needles)

Determine if a given string ends with a given substring.

Parameters

string|array $needles

Return Value

bool

bool exactly(string $value)

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

Parameters

string $value

Return Value

bool

Collection explode(string $delimiter, int $limit = PHP_INT_MAX)

Explode the string into an array.

Parameters

string $delimiter
int $limit

Return Value

Collection

Collection split(string|int $pattern, int $limit = -1, int $flags = 0)

Split a string using a regular expression or by length.

Parameters

string|int $pattern
int $limit
int $flags

Return Value

Collection

Stringable finish(string $cap)

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

Parameters

string $cap

Return Value

Stringable

bool is(string|array $pattern)

Determine if a given string matches a given pattern.

Parameters

string|array $pattern

Return Value

bool

bool isAscii()

Determine if a given string is 7 bit ASCII.

Return Value

bool

bool isEmpty()

Determine if the given string is empty.

Return Value

bool

bool isNotEmpty()

Determine if the given string is not empty.

Return Value

bool

Stringable kebab()

Convert a string to kebab case.

Return Value

Stringable

int length(string $encoding = null)

Return the length of the given string.

Parameters

string $encoding

Return Value

int

Stringable limit(int $limit = 100, string $end = '...')

Limit the number of characters in a string.

Parameters

int $limit
string $end

Return Value

Stringable

Stringable lower()

Convert the given string to lower-case.

Return Value

Stringable

Stringable|null match(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Stringable|null

Collection matchAll(string $pattern)

Get the string matching the given pattern.

Parameters

string $pattern

Return Value

Collection

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

Pad both sides of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

Stringable padLeft(int $length, string $pad = ' ')

Pad the left side of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

Stringable padRight(int $length, string $pad = ' ')

Pad the right side of the string with another.

Parameters

int $length
string $pad

Return Value

Stringable

array parseCallback(string|null $default = null)

Parse a Class@method style callback into class and method.

Parameters

string|null $default

Return Value

array

Stringable plural(int $count = 2)

Get the plural form of an English word.

Parameters

int $count

Return Value

Stringable

Stringable pluralStudly(int $count = 2)

Pluralize the last word of an English, studly caps case string.

Parameters

int $count

Return Value

Stringable

Stringable prepend(array ...$values)

Prepend the given values to the string.

Parameters

array ...$values

Return Value

Stringable

Stringable replace(string|string[] $search, string|string[] $replace)

Replace the given value in the given string.

Parameters

string|string[] $search
string|string[] $replace

Return Value

Stringable

Stringable replaceArray(string $search, array $replace)

Replace a given value in the string sequentially with an array.

Parameters

string $search
array $replace

Return Value

Stringable

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

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

Stringable replaceMatches(string $pattern, Closure|string $replace, int $limit = -1)

Replace the patterns matching the given regular expression.

Parameters

string $pattern
Closure|string $replace
int $limit

Return Value

Stringable

Stringable start(string $prefix)

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

Parameters

string $prefix

Return Value

Stringable

Stringable upper()

Convert the given string to upper-case.

Return Value

Stringable

Stringable title()

Convert the given string to title case.

Return Value

Stringable

Stringable singular()

Get the singular form of an English word.

Return Value

Stringable

Stringable slug(string $separator = '-', string|null $language = 'en')

Generate a URL friendly "slug" from a given string.

Parameters

string $separator
string|null $language

Return Value

Stringable

Stringable snake(string $delimiter = '_')

Convert a string to snake case.

Parameters

string $delimiter

Return Value

Stringable

bool startsWith(string|array $needles)

Determine if a given string starts with a given substring.

Parameters

string|array $needles

Return Value

bool

Stringable studly()

Convert a value to studly caps case.

Return Value

Stringable

Stringable substr(int $start, int|null $length = null)

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

Parameters

int $start
int|null $length

Return Value

Stringable

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

Returns the number of substring occurrences.

Parameters

string $needle
int|null $offset
int|null $length

Return Value

int

Stringable trim(string $characters = null)

Trim the string of the given characters.

Parameters

string $characters

Return Value

Stringable

Stringable ltrim(string $characters = null)

Left trim the string of the given characters.

Parameters

string $characters

Return Value

Stringable

Stringable rtrim(string $characters = null)

Right trim the string of the given characters.

Parameters

string $characters

Return Value

Stringable

Stringable ucfirst()

Make a string's first character uppercase.

Return Value

Stringable

mixed|$this when(mixed $value, callable $callback, callable|null $default = null)

Apply the callback's string changes if the given "value" is true.

Parameters

mixed $value
callable $callback
callable|null $default

Return Value

mixed|$this

Stringable whenEmpty(callable $callback)

Execute the given callback if the string is empty.

Parameters

callable $callback

Return Value

Stringable

Stringable words(int $words = 100, string $end = '...')

Limit the number of words in a string.

Parameters

int $words
string $end

Return Value

Stringable

$this dump()

Dump the string.

Return Value

$this

void dd()

Dump the string and end the script.

Return Value

void

mixed __get(string $key)

Proxy dynamic properties onto methods.

Parameters

string $key

Return Value

mixed

string __toString()

Get the raw string value.

Return Value

string

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Support/Stringable.html