class Stringable (View source)

Traits

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.

after(string $search)

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

afterLast(string $search)

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

append(array ...$values)

Append the given values to the string.

ascii(string $language = 'en')

Transliterate a UTF-8 value to ASCII.

basename(string $suffix = '')

Get the trailing name component of the path.

before(string $search)

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

beforeLast(string $search)

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

between(string $from, string $to)

Get the portion of a string between two given values.

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.

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.

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

Explode the string into an array.

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

Split a string using a regular expression.

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.

kebab()

Convert a string to kebab case.

int
length(string $encoding = null)

Return the length of the given string.

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

Limit the number of characters in a string.

lower()

Convert the given string to lower-case.

Stringable|null
match(string $pattern)

Get the string matching the given pattern.

matchAll(string $pattern)

Get the string matching the given pattern.

array
parseCallback(string|null $default = null)

Parse a [email protected] style callback into class and method.

plural(int $count = 2)

Get the plural form of an English word.

pluralStudly(int $count = 2)

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

prepend(array ...$values)

Prepend the given values to the string.

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

Replace the given value in the given string.

replaceArray(string $search, array $replace)

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

replaceFirst(string $search, string $replace)

Replace the first occurrence of a given value in the string.

replaceLast(string $search, string $replace)

Replace the last occurrence of a given value in the string.

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

Replace the patterns matching the given regular expression.

start(string $prefix)

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

upper()

Convert the given string to upper-case.

title()

Convert the given string to title case.

singular()

Get the singular form of an English word.

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

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

snake(string $delimiter = '_')

Convert a string to snake case.

bool
startsWith(string|array $needles)

Determine if a given string starts with a given substring.

studly()

Convert a value to studly caps case.

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.

trim(string $characters = null)

Trim the string of the given characters.

ltrim(string $characters = null)

Left trim the string of the given characters.

rtrim(string $characters = null)

Right trim the string of the given characters.

ucfirst()

Make a string's first character uppercase.

whenEmpty(callable $callback)

Execute the given callback if the string is empty.

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 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 $pattern, int $limit = -1, int $flags = 0)

Split a string using a regular expression.

Parameters

string $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

array parseCallback(string|null $default = null)

Parse a [email protected] 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

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