String
The string
service in the Streams Platform extends Laravel's \Illuminate\Support\Str
class.
Basic Usage
To use the Streams Platform string manipulation first include the \Anomaly\Streams\Platform\Support\Str
class.
Str::humanize()
The humanize
method humanizes slug type strings.
Returns: string
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$value |
true |
string |
none |
The value to humanize. |
$separator |
false |
string |
_ |
The slug separator used. This can help prevent breaking hyphenated words. |
Example
$str->humanize('default_table_name_example'); // default table name example
// Humanize is commonly used with ucwords.
ucwords($str->humanize('default_page')); // Default Page
Twig
{{ str_humanize('default_table_name_example') }} // default table name example
// Humanize is commonly used with ucwords.
{{ ucwords(str_humanize('default_page')) }} // Default Page
Str::truncate()
The truncate
is identical to Laravel's limit
method except that it preserves words.
Returns: string
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$value |
true |
string |
none |
The string value to truncate. |
$limit |
false |
integer |
100 |
The length to limit the value by. |
$end |
false |
string |
... |
The ending for the string only if truncated. |
Example
$str->truncate('The CMS built for everyone.', 10); // "The CMS..."
Twig
{{ str_truncate('The CMS built for everyone.', 10) }} // "The CMS..."
Str::linkify()
The linkify
method wraps URLs in link tags.
Returns: string
Arguments
Key | Required | Type | Default | Description |
---|---|---|---|---|
$text |
true |
string |
none |
The text to linkify. |
Example
$str->linkify('Checkout http://google.com!'); // Checkout <a href="http://google.com">http://google.com</a>!
Twig
{{ str_linkify('Checkout http://google.com!') }} // Checkout <a href="http://google.com">http://google.com</a>!
{{ 'Checkout http://google.com!'|str_linkify }} // Checkout <a href="http://google.com">http://google.com</a>!