class Illuminate / Support / Stringable
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

Stringable

Implements

Uses

Properties

protected

$value string

The underlying string value.

Default: null

Methods

public

__construct ( $value ) : void

Create a new instance of the class.

Parameters

  • $value string
public

after ( $search ) : static

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

Parameters

  • $search string
public

afterLast ( $search ) : static

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

Parameters

  • $search string
public

append ( $values ) : static

Append the given values to the string.

Parameters

  • $values array|string
public

newLine ( $count ) : $this

Append a new line to the string.

Parameters

  • $count int
public

ascii ( $language ) : static

Transliterate a UTF-8 value to ASCII.

Parameters

  • $language string
public

basename ( $suffix ) : static

Get the trailing name component of the path.

Parameters

  • $suffix string
public

charAt ( $index ) : string|false

Get the character at the specified index.

Parameters

  • $index int
public

classBasename ( ) : static

Get the basename of the class path.

public

before ( $search ) : static

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

Parameters

  • $search string
public

beforeLast ( $search ) : static

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

Parameters

  • $search string
public

between ( $from , $to ) : static

Get the portion of a string between two given values.

Parameters

  • $from string
  • $to string
public

betweenFirst ( $from , $to ) : static

Get the smallest possible portion of a string between two given values.

Parameters

  • $from string
  • $to string
public

camel ( ) : static

Convert a value to camel case.

public

contains ( $needles , $ignoreCase ) : bool

Determine if a given string contains a given substring.

Parameters

  • $needles string|iterable
  • $ignoreCase bool
public

containsAll ( $needles , $ignoreCase ) : bool

Determine if a given string contains all array values.

Parameters

  • $needles iterable
  • $ignoreCase bool
public

dirname ( $levels ) : static

Get the parent directory's path.

Parameters

  • $levels int
public

endsWith ( $needles ) : bool

Determine if a given string ends with a given substring.

Parameters

  • $needles string|iterable
public

exactly ( $value ) : bool

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

Parameters

public

excerpt ( $phrase , $options ) : string|null

Extracts an excerpt from text that matches the first instance of a phrase.

Parameters

  • $phrase string
  • $options array
public

explode ( $delimiter , $limit ) : Illuminate\...\Collection

Explode the string into an array.

Parameters

  • $delimiter string
  • $limit int
public

split ( $pattern , $limit , $flags ) : Illuminate\...\Collection

Split a string using a regular expression or by length.

Parameters

  • $pattern string|int
  • $limit int
  • $flags int
public

finish ( $cap ) : static

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

Parameters

  • $cap string
public

is ( $pattern ) : bool

Determine if a given string matches a given pattern.

Parameters

  • $pattern string|iterable
public

isAscii ( ) : bool

Determine if a given string is 7 bit ASCII.

public

isJson ( ) : bool

Determine if a given string is valid JSON.

public

isUrl ( ) : bool

Determine if a given value is a valid URL.

public

isUuid ( ) : bool

Determine if a given string is a valid UUID.

public

isUlid ( ) : bool

Determine if a given string is a valid ULID.

public

isEmpty ( ) : bool

Determine if the given string is empty.

public

isNotEmpty ( ) : bool

Determine if the given string is not empty.

public

kebab ( ) : static

Convert a string to kebab case.

public

length ( $encoding ) : int

Return the length of the given string.

Parameters

  • $encoding string|null
public

limit ( $limit , $end ) : static

Limit the number of characters in a string.

Parameters

  • $limit int
  • $end string
public

lower ( ) : static

Convert the given string to lower-case.

public

markdown ( array $options ) : static

Convert GitHub flavored Markdown into HTML.

Parameters

  • $options array
public

inlineMarkdown ( array $options ) : static

Convert inline Markdown into HTML.

Parameters

  • $options array
public

mask ( $character , $index , $length , $encoding ) : static

Masks a portion of a string with a repeated character.

Parameters

  • $character string
  • $index int
  • $length int|null
  • $encoding string
public

match ( $pattern ) : static

Get the string matching the given pattern.

Parameters

  • $pattern string
public

isMatch ( $pattern ) : bool

Determine if a given string matches a given pattern.

Parameters

  • $pattern string|iterable
public

matchAll ( $pattern ) : Illuminate\...\Collection

Get the string matching the given pattern.

Parameters

  • $pattern string
public

test ( $pattern ) : bool

Determine if the string matches the given pattern.

Parameters

  • $pattern string
public

padBoth ( $length , $pad ) : static

Pad both sides of the string with another.

Parameters

  • $length int
  • $pad string
public

padLeft ( $length , $pad ) : static

Pad the left side of the string with another.

Parameters

  • $length int
  • $pad string
public

padRight ( $length , $pad ) : static

Pad the right side of the string with another.

Parameters

  • $length int
  • $pad string
public

parseCallback ( $default ) : array|null>

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

Parameters

  • $default string|null
public

pipe ( callable $callback ) : static

Call the given callback and return a new string.

Parameters

  • $callback callable
public

plural ( $count ) : static

Get the plural form of an English word.

Parameters

public

pluralStudly ( $count ) : static

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

Parameters

public

prepend ( $values ) : static

Prepend the given values to the string.

Parameters

  • $values string
public

remove ( $search , $caseSensitive ) : static

Remove any occurrence of the given string in the subject.

Parameters

  • $search string|iterable
  • $caseSensitive bool
public

reverse ( ) : static

Reverse the string.

public

repeat ( int $times ) : static

Repeat the string.

Parameters

  • $times int
public

replace ( $search , $replace , $caseSensitive ) : static

Replace the given value in the given string.

Parameters

  • $search string|iterable
  • $replace string|iterable
  • $caseSensitive bool
public

replaceArray ( $search , $replace ) : static

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

Parameters

  • $search string
  • $replace iterable
public

replaceFirst ( $search , $replace ) : static

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

Parameters

  • $search string
  • $replace string
public

replaceLast ( $search , $replace ) : static

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

Parameters

  • $search string
  • $replace string
public

replaceMatches ( $pattern , $replace , $limit ) : static

Replace the patterns matching the given regular expression.

Parameters

  • $pattern string
  • $replace Closure |string
  • $limit int
public

scan ( $format ) : Illuminate\...\Collection

Parse input from a string to a collection, according to a format.

Parameters

  • $format string
public

squish ( ) : static

Remove all "extra" blank space from the given string.

public

start ( $prefix ) : static

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

Parameters

  • $prefix string
public

stripTags ( $allowedTags ) : static

Strip HTML and PHP tags from the given string.

Parameters

  • $allowedTags string
public

upper ( ) : static

Convert the given string to upper-case.

public

title ( ) : static

Convert the given string to title case.

public

headline ( ) : static

Convert the given string to title case for each word.

public

singular ( ) : static

Get the singular form of an English word.

public

slug ( $separator , $language , $dictionary ) : static

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

Parameters

  • $separator string
  • $language string|null
  • $dictionary array
public

snake ( $delimiter ) : static

Convert a string to snake case.

Parameters

  • $delimiter string
public

startsWith ( $needles ) : bool

Determine if a given string starts with a given substring.

Parameters

  • $needles string|iterable
public

studly ( ) : static

Convert a value to studly caps case.

public

substr ( $start , $length , $encoding ) : static

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

Parameters

  • $start int
  • $length int|null
  • $encoding string
public

substrCount ( $needle , $offset , $length ) : int

Returns the number of substring occurrences.

Parameters

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

substrReplace ( $replace , $offset , $length ) : static

Replace text within a portion of a string.

Parameters

  • $replace string|string[]
  • $offset int|int[]
  • $length int|int[]|null
public

swap ( array $map ) : static

Swap multiple keywords in a string with other keywords.

Parameters

  • $map array
public

trim ( $characters ) : static

Trim the string of the given characters.

Parameters

  • $characters string
public

ltrim ( $characters ) : static

Left trim the string of the given characters.

Parameters

  • $characters string
public

rtrim ( $characters ) : static

Right trim the string of the given characters.

Parameters

  • $characters string
public

lcfirst ( ) : static

Make a string's first character lowercase.

public

ucfirst ( ) : static

Make a string's first character uppercase.

public

ucsplit ( ) : Illuminate\...\Collection

Split a string by uppercase characters.

public

whenContains ( $needles , $callback , $default ) : static

Execute the given callback if the string contains a given substring.

Parameters

  • $needles string|iterable
  • $callback callable
  • $default callable|null
public

whenContainsAll ( array $needles , $callback , $default ) : static

Execute the given callback if the string contains all array values.

Parameters

  • $needles iterable
  • $callback callable
  • $default callable|null
public

whenEmpty ( $callback , $default ) : static

Execute the given callback if the string is empty.

Parameters

  • $callback callable
  • $default callable|null
public

whenNotEmpty ( $callback , $default ) : static

Execute the given callback if the string is not empty.

Parameters

  • $callback callable
  • $default callable|null
public

whenEndsWith ( $needles , $callback , $default ) : static

Execute the given callback if the string ends with a given substring.

Parameters

  • $needles string|iterable
  • $callback callable
  • $default callable|null
public

whenExactly ( $value , $callback , $default ) : static

Execute the given callback if the string is an exact match with the given value.

Parameters

  • $value string
  • $callback callable
  • $default callable|null
public

whenNotExactly ( $value , $callback , $default ) : static

Execute the given callback if the string is not an exact match with the given value.

Parameters

  • $value string
  • $callback callable
  • $default callable|null
public

whenIs ( $pattern , $callback , $default ) : static

Execute the given callback if the string matches a given pattern.

Parameters

  • $pattern string|iterable
  • $callback callable
  • $default callable|null
public

whenIsAscii ( $callback , $default ) : static

Execute the given callback if the string is 7 bit ASCII.

Parameters

  • $callback callable
  • $default callable|null
public

whenIsUuid ( $callback , $default ) : static

Execute the given callback if the string is a valid UUID.

Parameters

  • $callback callable
  • $default callable|null
public

whenIsUlid ( $callback , $default ) : static

Execute the given callback if the string is a valid ULID.

Parameters

  • $callback callable
  • $default callable|null
public

whenStartsWith ( $needles , $callback , $default ) : static

Execute the given callback if the string starts with a given substring.

Parameters

  • $needles string|iterable
  • $callback callable
  • $default callable|null
public

whenTest ( $pattern , $callback , $default ) : static

Execute the given callback if the string matches the given pattern.

Parameters

  • $pattern string
  • $callback callable
  • $default callable|null
public

words ( $words , $end ) : static

Limit the number of words in a string.

Parameters

  • $words int
  • $end string
public

wordCount ( $characters ) : int

Get the number of words a string contains.

Parameters

  • $characters string|null
public

wordWrap ( $characters , $break , $cutLongWords ) : static

Wrap a string to a given number of characters.

Parameters

  • $characters int
  • $break string
  • $cutLongWords bool
public

wrap ( $before , $after ) : static

Wrap the string with the given strings.

Parameters

  • $before string
  • $after string|null
public

toHtmlString ( ) : HtmlString

Convert the string into a HtmlString instance.

public

dump ( $args ) : $this

Dump the string.

Parameters

  • $args mixed
public

value ( ) : string

Get the underlying string value.

public

toString ( ) : string

Get the underlying string value.

public

toInteger ( ) : int

Get the underlying string value as an integer.

public

toFloat ( ) : float

Get the underlying string value as a float.

public

toBoolean ( ) : bool

Get the underlying string value as a boolean.

public

toDate ( $format , $tz ) : Carbon

Get the underlying string value as a Carbon instance.

Parameters

  • $format string|null
  • $tz string|null
public

jsonSerialize ( ) : string

Convert the object to a string when JSON encoded.

public

offsetExists ( mixed $offset ) : bool

Determine if the given offset exists.

Parameters

  • $offset mixed
public

offsetGet ( mixed $offset ) : string

Get the value at the given offset.

Parameters

  • $offset mixed
public

offsetSet ( mixed $offset , mixed $value ) : void

Set the value at the given offset.

Parameters

  • $offset mixed
public

offsetUnset ( mixed $offset ) : void

Unset the value at the given offset.

Parameters

  • $offset mixed
public

__get ( $key ) : mixed

Proxy dynamic properties onto methods.

Parameters

  • $key string
public

__toString ( ) : string

Get the raw string value.