Download the PHP package lukaswhite/string-utilities without Composer
On this page you can find all versions of the php package lukaswhite/string-utilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lukaswhite/string-utilities
More information about lukaswhite/string-utilities
Files in lukaswhite/string-utilities
Package string-utilities
Short Description Some miscellaneous string utilities for PHP
License MIT
Informations about the package string-utilities
String Utilities
A few miscellanous PHP string utilities.
Strip Punctuation
As the name suggests, the stripPunctuation()
method strips all punctuation from a string.
To avoid the addtional spaces where the dashes have been replaced, see
stripMultipleSpaces()
Strip Multiple Spaces
The stripMultipleSpaces()
strips multiple spaces:
Replace the nth Occurence of a Substring
If you have a string that contains multiple occurences of a given substring, but only want to replace a specific one, use replaceNth()
.
Replace All But First Occurence of a Substring
If you have a string that contains multiple occurences of a given substring, but want to replace all but the first one then use replaceAllButFirstOccurence()
.
Random Hex String
The randomHex()
method returns a random hexadecimal number, as a string, to the specified length.
To force it to be uppercase, pass true
as the second argument.
Starts With
Use startsWith()
to determine whether a string starts with a specified substring.
By default, the method is case sensitive. To make it case-insensitive, pass false
as a third argument.
Ends With
Use endsWith()
to determine whether a string ends with a specified substring.
By default, the method is case sensitive. To make it case-insensitive, pass false
as a third argument.
Generate an Excerpt
To generate an exceprt; as in, trim a string to a specified maximum number of words:
By default this appends ...
to the end of the string; change this using the optional third argument, for example:
Alternatively, if you need to limit the length of the excerpt to a specified number of characters: