Download the PHP package laraplus/string without Composer
On this page you can find all versions of the php package laraplus/string. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package string
Laraplus/String
This package provides a fluent easy-to-use interface for string manipulation. It integrates with Illuminate\Support to enable a fluent syntax even when dealing with multiple results. All methods are UTF-8 friendly.
Installation
To install this package, simply require it using composer:
Example usage
With this package you can avoid ugly nested str_* functions and never ending needle-haystack problems:
If you have a slug "my-blog-title-4" and you need to find the index "4", you can simply write:
Lets say you have some custom "colon separated" multi line string that you need to parse:
Full reference
Initialization
You can initialize the StringBuffer
object directly or by using the str
helper function:
Chaining
When the result of a method call is a string, it is automatically wrapped in a new StringBuffer instance, so that the method calls can be chained.
If you need to unwrap the object, you can do that by calling the get()
method or simply cast it to string.
When a method returns an array it is automatically wrapped in a Collection object, which enables further chaining:
For a full reference of available collection methods, see the Laravel documentation: http://laravel.com/docs/5.1/collections#available-methods
Available methods
ucfirst()
Capitalize the first letter of the string.
lcfirst()
Lowercase the first letter of the string.
startsWith($needles)
Determine if the string starts with a given substring.
endsWith($needles)
Determine if the string ends with a given substring.
contains($needles)
Determine if the string contains a given substring.
equals($needles)
Determine if the string equals the given input in a constant time comparison.
matches($pattern)
Determine if the string matches a given pattern.
explode($delimiters)
Split the string with given delimiter(s).
indexOf($needle, $offset = 0)
Find the first occurrence of a given needle in the string, starting at the provided offset.
lastIndexOf($needle, $offset = 0)
Find the last occurrence of a given needle in the string, starting at the provided offset.
replace($search, $replace, &$count = 0)
Replace all occurrences of the search string with the replacement string.
substring($start, $length = null)
Returns the portion of string specified by the start and length parameters
toAscii()
Transliterate a UTF-8 value to ASCII.
toCamel()
Convert a value to camel case.
toSnake()
Convert a value to snake case.
toStudly()
Convert a value to studly case.
toTitle()
Convert a value to title case.
toSlug()
Convert a value to title case.
toUpper()
Convert the given string to upper-case.
toLower()
Convert the given string to lower-case.
toSingular()
Get the singular form of an English word.
toPlural()
Get the plural form of an English word.
length()
Return the length of the given string.
words($ignore = '?!;:,.')
Return a Collection of individual words in the string ignoring the given characters.
lines()
Return a collection of individual lines in the string.
prepend($string)
Prepend a given input to the string.
append($string)
Append a given input to the string.
trim($chars = null)
Trim given characters from both ends of the string. If no characters are provided, all white space is trimmed.
ltrim($chars = null)
Similar to trim()
, but only trims characters from the left side.
rtrim($chars = null)
Similar to trim()
, but only trims characters from the right side.
limit($limit = 100, $end = '...')
Limit the number of characters in the string.
limitWords($limit = 100, $end = '...')
Limit the number of words in the string.
wordAt($index)
Return the word at the given index.
tree($open = '{', $close = '}')
Parse a tree structure defined by the given delimiters.
Using offsets
Since the StringBuffer class implements the ArrayAccess interface, you can also use all of the usual offset goodies: