# Stringable

The Stringable class exists in the `Mantle\Support` namespace and is used to create a stringable object from a string or a stringable object.

For more information see the [Laravel docs](https://laravel.com/docs/master/strings#method-str).

## Usage[​](#usage "Direct link to Usage")

```php
use function Mantle\Support\Helpers\stringable;

$string = stringable( 'String' ); // String

$string->append( 'append' )->lower(); // stringappend

```

## Available Methods[​](#available-methods "Direct link to Available Methods")

* [`after`](#after)
* [`after_last`](#after_last)
* [`append`](#append)
* [`newLine`](#newline)
* [`ascii`](#ascii)
* [`basename`](#basename)
* [`char_at`](#char_at)
* [`class_basename`](#class_basename)
* [`before`](#before)
* [`before_last`](#before_last)
* [`between`](#between)
* [`camel`](#camel)
* [`contains`](#contains)
* [`contains_all`](#contains_all)
* [`dirname`](#dirname)
* [`ends_with`](#ends_with)
* [`exactly`](#exactly)
* [`excerpt`](#excerpt)
* [`explode`](#explode)
* [`finish`](#finish)
* [`trailingSlash`](#trailingslash)
* [`untrailingSlash`](#untrailingslash)
* [`untrailing`](#untrailing)
* [`is`](#is)
* [`is_ascii`](#is_ascii)
* [`is_json`](#is_json)
* [`is_uuid`](#is_uuid)
* [`is_empty`](#is_empty)
* [`is_not_empty`](#is_not_empty)
* [`kebab`](#kebab)
* [`length`](#length)
* [`limit`](#limit)
* [`lower`](#lower)
* [`markdown`](#markdown)
* [`inline_markdown`](#inline_markdown)
* [`mask`](#mask)
* [`match`](#match)
* [`is_match`](#is_match)
* [`match_all`](#match_all)
* [`test`](#test)
* [`pad_both`](#pad_both)
* [`pad_left`](#pad_left)
* [`pad_right`](#pad_right)
* [`pipe`](#pipe)
* [`plural`](#plural)
* [`plural_studly`](#plural_studly)
* [`prepend`](#prepend)
* [`remove`](#remove)
* [`reverse`](#reverse)
* [`repeat`](#repeat)
* [`replace`](#replace)
* [`replace_array`](#replace_array)
* [`replace_first`](#replace_first)
* [`replace_last`](#replace_last)
* [`replace_matches`](#replace_matches)
* [`squish`](#squish)
* [`start`](#start)
* [`strip_tags`](#strip_tags)
* [`upper`](#upper)
* [`title`](#title)
* [`headline`](#headline)
* [`singular`](#singular)
* [`slug`](#slug)
* [`snake`](#snake)
* [`startsWith`](#startswith)
* [`studly`](#studly)
* [`studlyUnderscore`](#studlyunderscore)
* [`substr`](#substr)
* [`substr_count`](#substr_count)
* [`swap`](#swap)
* [`trim`](#trim)
* [`ltrim`](#ltrim)
* [`rtrim`](#rtrim)
* [`lcfirst`](#lcfirst)
* [`ucfirst`](#ucfirst)
* [`when_contains`](#when_contains)
* [`when_contains_all`](#when_contains_all)
* [`when_empty`](#when_empty)
* [`when_not_empty`](#when_not_empty)
* [`when_ends_with`](#when_ends_with)
* [`when_exactly`](#when_exactly)
* [`when_not_exactly`](#when_not_exactly)
* [`when_is`](#when_is)
* [`when_is_ascii`](#when_is_ascii)
* [`when_is_uuid`](#when_is_uuid)
* [`when_starts_with`](#when_starts_with)
* [`when_test`](#when_test)
* [`words`](#words)
* [`word_count`](#word_count)
* [`wrap`](#wrap)
* [`dump`](#dump)
* [`dd`](#dd)
* [`value`](#value)
* [`to_integer`](#to_integer)
* [`to_float`](#to_float)
* [`to_boolean`](#to_boolean)
* [`to_date`](#to_date)

### `after`[​](#after "Direct link to after")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example here' )->after( 'example ' ); // here

```

### `after_last`[​](#after_last "Direct link to after_last")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example again example here' )->after_last( 'example ' ); // here

```

### `append`[​](#append "Direct link to append")

Append a string or an array of strings to the end of the string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->append( 'append' ); // exampleappend
stringable( 'example' )->append( [ 'append1', 'append2' ] ); // exampleappend1append2

```

### `newLine`[​](#newline "Direct link to newline")

Return a string with a new line character.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->newLine(); // example\n
stringable( 'example' )->newLine( 2 ); // example\n\n

```

### `ascii`[​](#ascii "Direct link to ascii")

Transliterate a UTF-8 value to ASCII.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->ascii();

```

### `basename`[​](#basename "Direct link to basename")

Get the trailing name component of the path.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'Example/Path/To/File.txt' )->basename(); // File.txt

```

### `char_at`[​](#char_at "Direct link to char_at")

Get the character at a given index.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->char_at( 0 ); // e

```

### `class_basename`[​](#class_basename "Direct link to class_basename")

Get the class name from a fully qualified class name.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'Example\Namespace\ClassName' )->class_basename(); // ClassName

```

### `before`[​](#before "Direct link to before")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->before( 'ple' ); // ex

```

### `before_last`[​](#before_last "Direct link to before_last")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->before_last( 'ple' ); // exam

```

### `between`[​](#between "Direct link to between")

Return the portion of a string between two given values.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'abcdefgh' )->between( 'a', 'g' ); // bcdef

```

### `camel`[​](#camel "Direct link to camel")

Convert a string to camel case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'Example Name Here' )->camel(); // exampleNameHere

```

### `contains`[​](#contains "Direct link to contains")

Check if a string contains a given value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->contains( 'example' ); // true
stringable( 'example' )->contains( 'Example' ); // true
stringable( 'example' )->contains( 'Example', ignore_case: true ); // true

```

### `contains_all`[​](#contains_all "Direct link to contains_all")

Check if a string contains all of the given values.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->contains_all( [ 'example', 'here' ] ); // false
stringable( 'example here' )->contains_all( [ 'example', 'here' ] ); // true

```

### `dirname`[​](#dirname "Direct link to dirname")

Get the directory name of a path.

```php
use function Mantle\Support\Helpers\stringable;

stringable( '/example/path/to/file.txt' )->dirname(); // /example/path/to

```

### `ends_with`[​](#ends_with "Direct link to ends_with")

Check if a string ends with a given value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example here' )->ends_with( 'here' ); // true

```

### `exactly`[​](#exactly "Direct link to exactly")

Check if a string is exactly equal to a given value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->exactly( 'example' ); // true

```

### `excerpt`[​](#excerpt "Direct link to excerpt")

Get a string excerpt from a given string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'This is my example' )->excerpt( 'my', [ 'radius' => 3 ] ); // '...is my ex...'

```

### `explode`[​](#explode "Direct link to explode")

Explode a string into an array.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example here|example' )->explode( '|' ); // [ 'example here', 'example' ]

```

### `finish`[​](#finish "Direct link to finish")

Return the string with a given value appended to the end.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->finish( 'example' ); // exampleexample

```

### `trailingSlash`[​](#trailingslash "Direct link to trailingslash")

Return the string with a trailing slash.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->trailingSlash(); // example/

```

### `untrailingSlash`[​](#untrailingslash "Direct link to untrailingslash")

Return the string without a trailing slash.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example/' )->untrailingSlash(); // example

```

### `untrailing`[​](#untrailing "Direct link to untrailing")

Return the string without a given trailing value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example trim' )->untrailing( ' trim' ); // example

```

### `is`[​](#is "Direct link to is")

Check if a string matches a given pattern. Supports \* wildcards.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is( 'example' ); // true
stringable( 'example' )->is( 'ex*' ); // true
stringable( 'example' )->is( 'ex*ample' ); // true
stringable( 'example' )->is( 'ex*ample*' ); // true

```

### `is_ascii`[​](#is_ascii "Direct link to is_ascii")

Check if a string is ASCII.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_ascii(); // true

```

### `is_json`[​](#is_json "Direct link to is_json")

Check if a string is JSON.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_json(); // false
stringable( '{"example": "example"}' )->is_json(); // true

```

### `is_uuid`[​](#is_uuid "Direct link to is_uuid")

Check if a string is a valid UUID.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_uuid(); // false
stringable( '550e8400-e29b-41d4-a716-446655440000' )->is_uuid(); // true

```

### `is_empty`[​](#is_empty "Direct link to is_empty")

Check if a string is empty.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_empty(): bool; // false
stringable( '' )->is_empty(): bool; // true

```

### `is_not_empty`[​](#is_not_empty "Direct link to is_not_empty")

Check if a string is not empty.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_not_empty(): bool; // true
stringable( '' )->is_not_empty(): bool; // false

```

### `kebab`[​](#kebab "Direct link to kebab")

Convert a string to kebab case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->kebab(); // example
stringable( 'Example Name Here' )->kebab(); // example-name-here

```

### `length`[​](#length "Direct link to length")

Get the length of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->length(): int; // 7

```

### `limit`[​](#limit "Direct link to limit")

Limit the string to a given number of characters.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->limit( 3 ); // ex...
stringable( 'example' )->limit( 3, '... continue reading?' ); // ex... continue reading?

```

### `lower`[​](#lower "Direct link to lower")

Convert a string to lowercase.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'Example' )->lower(); // example

```

### `markdown`[​](#markdown "Direct link to markdown")

Convert GitHub flavored Markdown into HTML.

```php
use function Mantle\Support\Helpers\stringable;

stringable( "# Example\nText here" )->markdown(); // <h1>Example</h1><p>Text here</p>

```

### `inline_markdown`[​](#inline_markdown "Direct link to inline_markdown")

Convert inline Markdown into HTML.

```php
use function Mantle\Support\Helpers\stringable;

stringable( "# Example\nText here" )->inline_markdown(); // <h1>Example</h1><p>Text here</p>

```

### `mask`[​](#mask "Direct link to mask")

Masks a portion of a string with a repeated character.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example@example.com' )->mask( '*', 3 ); // exa****************

```

### `match`[​](#match "Direct link to match")

Get the string matching the given pattern.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->match( /exam/ ); // exam

```

### `is_match`[​](#is_match "Direct link to is_match")

Check if a string matches a given pattern.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->is_match( /exam/ ); // true

```

### `match_all`[​](#match_all "Direct link to match_all")

Get the string matching the given pattern.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->match_all( /exam/ ); // [ 'exam' ]

```

### `test`[​](#test "Direct link to test")

Check if a string matches a given pattern.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->test( /exam/ ); // true

```

### `pad_both`[​](#pad_both "Direct link to pad_both")

Pad a string to the left and right to a given length.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->pad_both( '_', 3 ); // ___example___

```

### `pad_left`[​](#pad_left "Direct link to pad_left")

Pad a string to the left to a given length.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->pad_left( '_', 3 ); // ___example

```

### `pad_right`[​](#pad_right "Direct link to pad_right")

Pad a string to the right to a given length.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->pad_right( 3, '_' ); // example___

```

### `pipe`[​](#pipe "Direct link to pipe")

Pipe the string to a given callback and return the result as a stringable object.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->pipe( 'md5' ); // md5'd value in Stringable object.

```

### `plural`[​](#plural "Direct link to plural")

Get the plural form of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->plural(); // examples
stringable( 'example' )->plural( 2 ); // examples
stringable( 'example' )->plural( 1 ); // example

```

### `plural_studly`[​](#plural_studly "Direct link to plural_studly")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->plural_studly(); // Examples
stringable( 'example' )->plural_studly( 2 ); // Examples
stringable( 'example' )->plural_studly( 1 ); // Example

```

### `prepend`[​](#prepend "Direct link to prepend")

Prepend a string or an array of strings to the beginning of the string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->prepend( 'prepend' ); // prependexample

```

### `remove`[​](#remove "Direct link to remove")

Remove a string or an array of strings from the string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->remove( 'exam' ); // ple

```

### `reverse`[​](#reverse "Direct link to reverse")

Reverse the string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->reverse(); // elpmaxe

```

### `repeat`[​](#repeat "Direct link to repeat")

Repeat the string a given number of times.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->repeat( 3 ); // exampleexampleexample

```

### `replace`[​](#replace "Direct link to replace")

Replace all occurrences of a given value in the string with another value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->replace( 'example', 'replace' ); // replace

```

### `replace_array`[​](#replace_array "Direct link to replace_array")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->replace_array( 'example', [ 'replace1', 'replace2' ] ); // replace1replace2

```

### `replace_first`[​](#replace_first "Direct link to replace_first")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->replace_first( 'example', 'replace' ); // replace

```

### `replace_last`[​](#replace_last "Direct link to replace_last")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->replace_last( 'example', 'replace' ); // replace

```

### `replace_matches`[​](#replace_matches "Direct link to replace_matches")

Replace all occurrences of a given pattern in the string with a value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->replace_matches( /([a-z]+)/, 'replace' ); // replace

```

### `squish`[​](#squish "Direct link to squish")

Remove all whitespace from the beginning and end of a string, and reduce multiple spaces to a single space.

```php
use function Mantle\Support\Helpers\stringable;

stringable( '  example ' )->squish(); // example

```

### `start`[​](#start "Direct link to start")

Return the string with a given value prepended to the beginning.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->start( 'pre' ); // preexample

```

### `strip_tags`[​](#strip_tags "Direct link to strip_tags")

Strip HTML tags from a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( '<p>example</p>' )->strip_tags(); // example

```

### `upper`[​](#upper "Direct link to upper")

Convert a string to uppercase.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->upper(); // EXAMPLE

```

### `title`[​](#title "Direct link to title")

Convert a string to title case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example string here' )->title(); // Example String Here

```

### `headline`[​](#headline "Direct link to headline")

Convert a string to headline case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example string here' )->headline(); // Example String Here

```

### `singular`[​](#singular "Direct link to singular")

Get the singular form of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'examples' )->singular(); // example

```

### `slug`[​](#slug "Direct link to slug")

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

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example word here' )->slug(); // example-word-here
stringable( 'example word here' )->slug( '_' ); // example_word_here

```

### `snake`[​](#snake "Direct link to snake")

Convert a string to snake case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example name here' )->snake(); // example_name_here

```

### `startsWith`[​](#startswith "Direct link to startswith")

Check if a string starts with a given value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->startsWith( 'example' ); // true

```

### `studly`[​](#studly "Direct link to studly")

Convert a string to studly caps case.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example name here' )->studly(); // ExampleNameHere

```

### `studlyUnderscore`[​](#studlyunderscore "Direct link to studlyunderscore")

Convert a string to studly caps case with underscores.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example name here' )->studlyUnderscore(); // Example_Name_Here

```

### `substr`[​](#substr "Direct link to substr")

Get a substring of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->substr( 2, 3 ); // amp

```

### `substr_count`[​](#substr_count "Direct link to substr_count")

Count the number of occurrences of a substring in a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example here' )->substr_count( 'e' ); // 2

```

### `swap`[​](#swap "Direct link to swap")

Replace all occurrences of a given value in the string with another value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example words here', [ 'example' => 'some', 'here' => 'there' ] ); // some words there

```

### `trim`[​](#trim "Direct link to trim")

Trim whitespace from the beginning and end of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( ' example ' )->trim(); // example

```

### `ltrim`[​](#ltrim "Direct link to ltrim")

Trim whitespace from the beginning of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( ' example ' )->ltrim(); // 'example '

```

### `rtrim`[​](#rtrim "Direct link to rtrim")

Trim whitespace from the end of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( ' example ' )->rtrim(); // ' example'

```

### `lcfirst`[​](#lcfirst "Direct link to lcfirst")

Convert the first character of a string to lowercase.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'Example' )->lcfirst(); // example

```

### `ucfirst`[​](#ucfirst "Direct link to ucfirst")

Convert the first character of a string to uppercase.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->ucfirst(); // Example

```

### `when_contains`[​](#when_contains "Direct link to when_contains")

Check if a string contains a given value and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_contains( string|iterable<string> $needles, ?callable $callback, ?callable $default = null );

```

### `when_contains_all`[​](#when_contains_all "Direct link to when_contains_all")

Check if a string contains all of the given values and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_contains_all( array<string> $needles, ?callable $callback, ?callable $default = null );

```

### `when_empty`[​](#when_empty "Direct link to when_empty")

Check if a string is empty and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_empty( ?callable $callback, ?callable $default = null );

```

### `when_not_empty`[​](#when_not_empty "Direct link to when_not_empty")

Check if a string is not empty and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_not_empty( ?callable $callback, ?callable $default = null );

```

### `when_ends_with`[​](#when_ends_with "Direct link to when_ends_with")

Check if a string ends with a given value and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_ends_with( string|iterable<string> $needles, ?callable $callback, ?callable $default = null );

```

### `when_exactly`[​](#when_exactly "Direct link to when_exactly")

Check if a string is exactly equal to a given value and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_exactly( string $value, ?callable $callback, ?callable $default = null );

```

### `when_not_exactly`[​](#when_not_exactly "Direct link to when_not_exactly")

Check if a string is not exactly equal to a given value and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_not_exactly( string $value, ?callable $callback, ?callable $default = null );

```

### `when_is`[​](#when_is "Direct link to when_is")

Check if a string matches a given pattern and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_is( string|iterable<string> $pattern, ?callable $callback, ?callable $default = null );

```

### `when_is_ascii`[​](#when_is_ascii "Direct link to when_is_ascii")

Check if a string is ASCII and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_is_ascii( ?callable $callback, ?callable $default = null );

```

### `when_is_uuid`[​](#when_is_uuid "Direct link to when_is_uuid")

Check if a string is a valid UUID and execute a callback if it is.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_is_uuid( ?callable $callback, ?callable $default = null );

```

### `when_starts_with`[​](#when_starts_with "Direct link to when_starts_with")

Check if a string starts with a given value and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_starts_with( string|iterable<string> $needles, ?callable $callback, ?callable $default = null );

```

### `when_test`[​](#when_test "Direct link to when_test")

Check if a string matches a given pattern and execute a callback if it does.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->when_test( string $pattern, ?callable $callback, ?callable $default = null );

```

### `words`[​](#words "Direct link to words")

Get the first `n` words of a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->words( int $words = 100, string $end = '...' );

```

### `word_count`[​](#word_count "Direct link to word_count")

Get the number of words in a string.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->word_count( string|null $characters = null ): int;

```

### `wrap`[​](#wrap "Direct link to wrap")

Wrap a string with a given value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->wrap( string $before, string|null $after = null );

```

### `dump`[​](#dump "Direct link to dump")

Dump the string and return it as a stringable object.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->dump();

```

### `dd`[​](#dd "Direct link to dd")

Dump the string and terminate the script.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->dd(): never;

```

### `value`[​](#value "Direct link to value")

Get the string value.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->value(): string;

```

### `to_integer`[​](#to_integer "Direct link to to_integer")

Convert the string to an integer.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->to_integer(): int;

```

### `to_float`[​](#to_float "Direct link to to_float")

Convert the string to a float.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->to_float(): float;

```

### `to_boolean`[​](#to_boolean "Direct link to to_boolean")

Convert the string to a boolean.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->to_boolean(): bool;

```

### `to_date`[​](#to_date "Direct link to to_date")

Convert the string to a Carbon date object.

```php
use function Mantle\Support\Helpers\stringable;

stringable( 'example' )->to_date( string|null $format = null, string|null $tz = null ): ?\Carbon\Carbon;

```
