Download the PHP package conkal/ztring without Composer
On this page you can find all versions of the php package conkal/ztring. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download conkal/ztring
More information about conkal/ztring
Files in conkal/ztring
Informations about the package ztring
ztring
A PHP string manipulation library.
- Installation
- OO and Chaining
- Class methods
append prepend camelcase count at chars collapseWhitespace endsWith ensureLeft ensureRight firstChar firstXChars lastChar lastXChars length lowerCaseFirst prepend replace reverse random slug startsWith substr swapCase removeWhiteSpace lowerCase toBoolean ascii trim words sanitize acronym number
Installation
OO and Chaining
The library offers OO method chaining, as seen below:
Conkal\ztring
has a __toString() method, which returns the current string
when the object is used in a string context, ie:
(string) ztring::create('foo') // 'foo'
Implemented Interfaces
Conkal\ztring
implements the IteratorAggregate
interface, meaning that
foreach
can be used with an instance of the class:
It implements the Countable
interface, enabling the use of count()
to
retrieve the number of characters in the string:
Furthermore, the ArrayAccess
interface has been implemented. As a result,
isset()
can be used to check if a character at a specific index exists. And
since Conkal\ztring
is immutable, any call to offsetSet
or offsetUnset
will throw an exception. offsetGet
has been implemented, however, and accepts
both positive and negative indexes. Invalid indexes result in an
OutOfBoundsException
.
Class methods
create(string $str)
Creates a ztring object and assigns string property. $str is cast to a string prior to assignment.
Instance Methods
append(string $string)
Returns a new string with $string appended.
at(int $index)
Returns the character at $index, with indexes starting at 0.
camelcase()
Returns a camelCase version of the string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.
chars()
Returns an array consisting of the characters in the string.
collapseWhitespace()
Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.
endsWith(string $substring [, boolean $caseSensitive = true ])
Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
ensureLeft(string $substring)
Ensures that the string begins with $substring. If it doesn't, it's prepended.
ensureRight(string $substring)
Ensures that the string ends with $substring. If it doesn't, it's appended.
firstChar()
Returns the first $n characters of the string.
firstXChars()
Returns the first $n characters of the string.
lastChar()
Returns the last $n characters of the string.
lastXChars()
Returns the last $n characters of the string.
length()
Returns the length of the string. An alias for PHP's mb_strlen() function.
lowerCaseFirst()
Converts the first character of the supplied string to lower case.
prepend(string $string)
Returns a new string starting with $string.
removeLeft(string $substring)
Returns a new string with the prefix $substring removed, if present.
replace(string $search, string $replacement)
Replaces all occurrences of $search in $str by $replacement.
reverse()
Returns a reversed string. A multibyte version of strrev().
random()
Create a random string
slug( [string $separator = '-'])
startsWith(string $substring [, boolean $caseSensitive = true ])
Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
substr(int $start [, int $length ])
Returns the substring beginning at $start with the specified $length. It differs from the mb_substr() function in that providing a $length of null will return the rest of the string, rather than an empty string.
swapCase()
Returns a case swapped version of the string.
titleCase()
Returns a trimmed string with the first letter of each word capitalized.
ascii($languageSpecific)
Returns an ASCII version of the string.
toBoolean()
Returns a boolean representation of the given logical string value. For example, 'true', '1', 'on' and 'yes' will return true. 'false', '0', 'off', and 'no' will return false. In all instances, case is ignored.
toLowerCase()
Converts all characters in the string to lowercase. An alias for PHP's mb_strtolower().
toTitleCase()
Converts the first character of each word in the string to uppercase.
uppercase()
Converts all characters in the string to uppercase. An alias for PHP's mb_strtoupper().
trim([, string $chars])
Returns a string with whitespace removed from the start and end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
upperCaseFirst()
Converts the first character of the supplied string to upper case.
words()
Returns words as array
sanitize()
Removes all special characters
acronym()
Creates an acronym
number()
return only digits between 0-9
Tests
From the project directory, tests can be ran using phpunit
License
Released under the MIT License - see LICENSE.txt
for details.
All versions of ztring with dependencies
ext-mbstring Version *
ext-openssl Version *