A PHP string manipulation library with multibyte support. Compatible with PHP 7+
100% compatible with the original "Stringy" library, but this fork is optimized for performance and is using PHP 7+ features.
s('string')->toTitleCase()->ensureRight('y') == 'Stringy'
- Why?
- Alternative
- Installation
- OO and Chaining
- Implemented Interfaces
- PHP Class Call Creation
- Class methods
- Instance methods
- append
- appendPassword
- appendUniqueIdentifier
- appendRandomString
- at
- between
- camelize
- capitalizePersonName
- chars
- collapseWhitespace
- contains
- containsAll
- containsAny
- countSubstr
- dasherize
- delimit
- endsWith
- endsWithAny
- ensureLeft
- ensureRight
- extractText
- first
- escape
- getEncoding
- hasLowerCase
- hasUpperCase
- htmlDecode
- htmlEncode
- humanize
- indexOf
- indexOfLast
- insert
- is
- isAlpha
- isAlphanumeric
- isBase64
- isBlank
- isHexadecimal
- isJson
- isLowerCase
- isSerialized
- isUpperCase
- last
- length
- lines
- longestCommonPrefix
- longestCommonSuffix
- longestCommonSubstring
- lowerCaseFirst
- pad
- padBoth
- padLeft
- padRight
- prepend
- regexReplace
- removeLeft
- removeRight
- removeHtml
- removeHtmlBreak
- removeXss
- repeat
- replace
- reverse
- safeTruncate
- shuffle
- slugify
- stripeCssMediaQueries
- stripeEmptyHtmlTags
- stripWhitespace
- startsWith
- startsWithAny
- slice
- split
- substr
- surround
- swapCase
- tidy
- titleize
- toAscii
- toBoolean
- toLowerCase
- toSpaces
- toTabs
- toTitleCase
- toUpperCase
- trim
- trimLeft
- trimRight
- truncate
- underscored
- upperCamelize
- upperCaseFirst
- utf8ify
- Extensions
- Tests
- License
In part due to a lack of multibyte support (including UTF-8) across many of
PHP's standard string functions. But also to offer an OO wrapper around the
mbstring
module's multibyte-compatible functions. Stringy handles some quirks,
provides additional functionality, and hopefully makes strings a little easier
to work with!
// Standard library
strtoupper('fòôbàř'); // 'FòôBàř'
strlen('fòôbàř'); // 10
// mbstring
mb_strtoupper('fòôbàř'); // 'FÒÔBÀŘ'
mb_strlen('fòôbàř'); // '6'
// Stringy
$stringy = Stringy\Stringy::create('fòôbàř');
$stringy->toUpperCase(); // 'FÒÔBÀŘ'
$stringy->length(); // '6'
If you like a more Functional Way to edit strings, then you can take a look at voku/portable-utf8, also "voku/Stringy" used the functions from the "Portable UTF-8"-Class but in a more Object Oriented Way.
// Portable UTF-8
use voku\helper\UTF8;
UTF8::strtoupper('fòôbàř'); // 'FÒÔBÀŘ'
UTF8::strlen('fòôbàř'); // '6'
composer require voku/stringy
If you're using Composer to manage dependencies, you can include the following in your composer.json file:
"require": {
"voku/stringy": "~6.0"
}
Then, after running composer update
or php composer.phar update
, you can
load the class using Composer's autoloading:
require 'vendor/autoload.php';
Otherwise, you can simply require the file directly:
require_once 'path/to/Stringy/src/Stringy.php';
And in either case, I'd suggest using an alias.
use Stringy\Stringy as S;
The library offers OO method chaining, as seen below:
use Stringy\Stringy as S;
echo S::create('fòô bàř')->collapseWhitespace()->swapCase(); // 'FÒÔ BÀŘ'
Stringy\Stringy
has a __toString() method, which returns the current string
when the object is used in a string context, ie:
(string) S::create('foo') // 'foo'
Stringy\Stringy
implements the IteratorAggregate
interface, meaning that
foreach
can be used with an instance of the class:
$stringy = S::create('fòôbàř');
foreach ($stringy as $char) {
echo $char;
}
// 'fòôbàř'
It implements the Countable
interface, enabling the use of count()
to
retrieve the number of characters in the string:
$stringy = S::create('fòô');
count($stringy); // 3
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 Stringy\Stringy
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
.
$stringy = S::create('bàř');
echo $stringy[2]; // 'ř'
echo $stringy[-2]; // 'à'
isset($stringy[-4]); // false
$stringy[3]; // OutOfBoundsException
$stringy[2] = 'a'; // Exception
As of PHP 5.6+, use function
is
available for importing functions. Stringy exposes a namespaced function,
Stringy\create
, which emits the same behaviour as Stringy\Stringy::create()
.
use function Stringy\create as s;
// Instead of: S::create('fòô bàř')
s('fòô bàř')->collapseWhitespace()->swapCase();
Creates a Stringy object and assigns both str and encoding properties the supplied values. $str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding(). It then returns the initialized object. Throws an InvalidArgumentException if the first argument is an array or object without a __toString method.
$stringy = S::create('fòôbàř', 'UTF-8'); // 'fòôbàř'
If you need a collection of Stringy objects you can use the S::collection() method.
$stringyCollection = \Stringy\collection(['fòôbàř', 'lall', 'öäü']);
Stringy objects are immutable. All examples below make use of PHP 5.6 function importing, and PHP 5.4 short array syntax. They also assume the encoding returned by mb_internal_encoding() is UTF-8. For further details, see the documentation for the create method above, as well as the notes on PHP 5.6 creation.
Gets the substring after the first occurrence of a separator.
s('</b></b>')->afterFirst('b'); // '></b>'
Gets the substring after the first occurrence of a separator.
s('</B></B>')->afterFirstIgnoreCase('b'); // '></B>'
Gets the substring after the last occurrence of a separator.
s('</b></b>')->afterLast('b'); // '>'
Gets the substring after the last occurrence of a separator.
s('</B></B>')->afterLastIgnoreCase('b'); // '>'
Returns a new string with $string appended.
s('fòô')->append('bàř'); // 'fòôbàř'
Append an password (limited to chars that are good readable).
s('')->appendPassword(8); // e.g.: '89bcdfgh'
Append an unique identifier.
s('')->appendUniqueIdentifier(); // e.g.: '1f3870be274f6c49b3e31a0c6728957f'
Append an random string.
s('')->appendUniqueIdentifier(5, 'ABCDEFGHI'); // e.g.: 'CDEHI'
Returns the character at $index, with indexes starting at 0.
s('fòôbàř')->at(3); // 'b'
Gets the substring before the first occurrence of a separator.
s('</b></b>')->beforeFirst('b'); // '</'
Gets the substring before the first occurrence of a separator.
s('</B></B>')->beforeFirstIgnoreCase('b'); // '</'
Gets the substring before the last occurrence of a separator.
s('</b></b>')->beforeLast('b'); // '</b></'
Gets the substring before the last occurrence of a separator.
s('</B></B>')->beforeLastIgnoreCase('b'); // '</B></'
Returns the substring between $start and $end, if found, or an empty string. An optional offset may be supplied from which to begin the search for the start string.
s('{foo} and {bar}')->between('{', '}'); // 'foo'
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.
s('Camel-Case')->camelize(); // 'camelCase'
Returns the string with the first letter of each word capitalized, except for when the word is a name which shouldn't be capitalized.
s('jaap de hoop scheffer')->capitalizePersonName(); // 'Jaap de Hoop Scheffer'
Returns an array consisting of the characters in the string.
s('fòôbàř')->chars(); // ['f', 'ò', 'ô', 'b', 'à', 'ř']
Splits the string into chunks of Stringy objects.
You can also take a look at "split" if you need to split the string by some chars into chunks.
s('foobar')->chunk(3); // ['foo', 'bar']
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.
s(' Ο συγγραφέας ')->collapseWhitespace(); // 'Ο συγγραφέας'
Returns true if the string contains $needle, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('Ο συγγραφέας είπε')->contains('συγγραφέας'); // true
Returns true if the string contains all $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('foo & bar')->containsAll(['foo', 'bar']); // true
Returns true if the string contains any $needles, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('str contains foo')->containsAny(['foo', 'bar']); // true
Returns the number of occurrences of $substring in the given string. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('Ο συγγραφέας είπε')->countSubstr('α'); // 2
Returns a lowercase and trimmed string separated by dashes. Dashes are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as underscores.
s('fooBar')->dasherize(); // 'foo-bar'
Returns a lowercase and trimmed string separated by the given delimiter. Delimiters are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces, dashes, and underscores. Alpha delimiters are not converted to lowercase.
s('fooBar')->delimit('::'); // 'foo::bar'
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.
s('fòôbàř')->endsWith('bàř', true); // true
Returns true if the string ends with any of $substrings, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('fòôbàř')->endsWith(['bàř', 'baz'], true); // true
Ensures that the string begins with $substring. If it doesn't, it's prepended.
s('foobar')->ensureLeft('http://'); // 'http://foobar'
Ensures that the string ends with $substring. If it doesn't, it's appended.
s('foobar')->ensureRight('.com'); // 'foobar.com'
Escape html via htmlspecialchars(), so we can use this data in our templates.
s('<∂∆ onerror="alert(xss)">')->escape(); // '<∂∆ onerror="alert(xss)">'
Create an extract from a sentence, so if the search-string was found, it try to centered in the output.
$sentence = 'This is only a Fork of Stringy, take a look at the new features.';
s($sentence)->extractText('Stringy'); // '...Fork of Stringy...'
Return a formatted string via sprintf + named parameters via array syntax.
$input = 'one: %2$d, %1$s: 2, %:text_three: %3$d';
s($input)->format(['text_three' => '%4$s'], 'two', 1, 3, 'three'); // 'One: 1, two: 2, three: 3'
Returns the first $n characters of the string.
s('fòôbàř')->first(3); // 'fòô'
Returns the encoding used by the Stringy object.
s('fòôbàř', 'UTF-8')->getEncoding(); // 'UTF-8'
Returns true if the string contains a lower case char, false otherwise.
s('fòôbàř')->hasLowerCase(); // true
Returns true if the string contains an upper case char, false otherwise.
s('fòôbàř')->hasUpperCase(); // false
Convert all HTML entities to their applicable characters. An alias of html_entity_decode. For a list of flags, refer to http://php.net/manual/en/function.html-entity-decode.php
s('&')->htmlDecode(); // '&'
Convert all applicable characters to HTML entities. An alias of htmlentities. Refer to http://php.net/manual/en/function.htmlentities.php for a list of flags.
s('&')->htmlEncode(); // '&'
Capitalizes the first word of the string, replaces underscores with spaces, and strips '_id'.
s('author_id')->humanize(); // 'Author'
Returns the index of the first occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. A negative index searches from the end
s('string')->indexOf('ing'); // 3
Returns the index of the first occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. A negative index searches from the end
s('string')->indexOfIgnoreCase('ING'); // 3
Returns the index of the last occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. Offsets may be negative to count from the last character in the string.
s('foobarfoo')->indexOfLast('foo'); // 10
Returns the index of the last occurrence of $needle in the string, and false if not found. Accepts an optional offset from which to begin the search. Offsets may be negative to count from the last character in the string.
s('fooBarFoo')->indexOfLastIgnoreCase('foo'); // 10
Inserts $substring into the string at the $index provided.
s('fòôbř')->insert('à', 4); // 'fòôbàř'
Returns true if the string contains the $pattern.
WARNING: Asterisks ("*") are translated into (".*") zero-or-more regular expression wildcards.
s('Foo\\Bar\\Lall')->is('*\\Bar\\*'); // true
Returns true if the string contains only alphabetic chars, false otherwise.
s('丹尼爾')->isAlpha(); // true
Returns true if the string contains only alphabetic and numeric chars, false otherwise.
s('دانيال1')->isAlphanumeric(); // true
Returns true if the string is base64 encoded, false otherwise.
s('Zm9vYmFy')->isBase64(); // true
Returns true if the string contains only whitespace chars, false otherwise.
s("\n\t \v\f")->isBlank(); // true
Returns true if the string contains a valid E-Mail address, false otherwise.
Determine whether the string is considered to be empty.
A variable is considered empty if it does not exist or if its value equals FALSE.
s('')->isEmpty(); // true
Determine whether the string is considered to be NOT empty.
A variable is considered NOT empty if it does exist or if its value equals TRUE.
s('')->isNotEmpty(); // false
Determine whether the string is equals to $str.
s('foo')->isEquals('foo'); // true
Returns true if the string contains only hexadecimal chars, false otherwise.
s('A102F')->isHexadecimal(); // true
Returns true if the string contains HTML-Tags, false otherwise.
s('<h1>foo</h1>')->isHtml(); // true
Returns true if the string is JSON, false otherwise. Unlike json_decode in PHP 5.x, this method is consistent with PHP 7 and other JSON parsers, in that an empty string is not considered valid JSON.
s('{"foo":"bar"}')->isJson(); // true
Returns true if the string contains only lower case chars, false otherwise.
s('fòôbàř')->isLowerCase(); // true
Returns true if the string is serialized, false otherwise.
s('a:1:{s:3:"foo";s:3:"bar";}')->isSerialized(); // true
Returns true if the string contains only upper case chars, false otherwise.
s('FÒÔBÀŘ')->isUpperCase(); // true
Returns the last $n characters of the string.
s('fòôbàř')->last(3); // 'bàř'
Returns the length of the string.
s('fòôbàř')->length(); // 6
Splits on newlines and carriage returns, returning an array of Stringy objects corresponding to the lines in the string.
s("fòô\r\nbàř\n")->lines(); // ['fòô', 'bàř', '']
Returns the longest common prefix between the string and $otherStr.
s('foobar')->longestCommonPrefix('foobaz'); // 'fooba'
Returns the longest common suffix between the string and $otherStr.
s('fòôbàř')->longestCommonSuffix('fòrbàř'); // 'bàř'
Returns the longest common substring between the string and $otherStr. In the case of ties, it returns that which occurs first.
s('foobar')->longestCommonSubstring('boofar'); // 'oo'
Converts the first character of the supplied string to lower case.
s('Σ foo')->lowerCaseFirst(); // 'σ foo'
Pads the string to a given length with $padStr. If length is less than or equal to the length of the string, no padding takes places. The default string used for padding is a space, and the default type (one of 'left', 'right', 'both') is 'right'. Throws an InvalidArgumentException if $padType isn't one of those 3 values.
s('fòôbàř')->pad(9, '-/', 'left'); // '-/-fòôbàř'
Returns a new string of a given length such that both sides of the string string are padded. Alias for pad() with a $padType of 'both'.
s('foo bar')->padBoth(9, ' '); // ' foo bar '
Returns a new string of a given length such that the beginning of the string is padded. Alias for pad() with a $padType of 'left'.
s('foo bar')->padLeft(9, ' '); // ' foo bar'
Returns a new string of a given length such that the end of the string is padded. Alias for pad() with a $padType of 'right'.
s('foo bar')->padRight(10, '_*'); // 'foo bar_*_'
Returns a new string starting with $string.
s('bàř')->prepend('fòô'); // 'fòôbàř'
Replaces all occurrences of $pattern in $str by $replacement. An alias for mb_ereg_replace(). Note that the 'i' option with multibyte patterns in mb_ereg_replace() requires PHP 5.6+ for correct results. This is due to a lack of support in the bundled version of Oniguruma in PHP < 5.6, and current versions of HHVM (3.8 and below).
s('fòô ')->regexReplace('f[òô]+\s', 'bàř'); // 'bàř'
s('fò')->regexReplace('(ò)', '\\1ô'); // 'fòô'
Returns a new string with the prefix $substring removed, if present.
s('fòôbàř')->removeLeft('fòô'); // 'bàř'
Returns a new string with the suffix $substring removed, if present.
s('fòôbàř')->removeRight('bàř'); // 'fòô'
Returns a new string without "breaks" (<br .*>, \n, \r\n, ...).
s('řàb <ô>òf\', ô<br/>foo <a href="#">lall</a>')->removeHtml(' '); // 'řàb <ô>òf\', ô< foo <a href="#">lall</a>'
Returns a new string without HTML-Tags.
s('řàb <ô>òf\', ô<br/>foo <a href="#">lall</a>')->removeHtml('<br><br/>'); // 'řàb òf\', ô<br/>foo lall'
Returns a new string without XSS.
s('<IMG SRC=javascript:alert('XSS')>')->removeXss(); // '<IMG >'
Returns a repeated string given a multiplier. An alias for str_repeat.
s('α')->repeat(3); // 'ααα'
shorten the string after $length, but also after the next word
s('this is a test')->shorten(5, '...'); // 'this...'
Replaces all occurrences of $search in $str by $replacement.
s('fòô bàř fòô bàř')->replace('fòô ', ''); // 'bàř bàř'
Replaces all occurrences of elements from $search in $str by $replacement.
s('fòô bàř lall bàř')->replace(['fòÔ ', 'lall'], '', false); // 'bàř bàř'
Replaces all occurrences of $search in $str by $replacement.
s('fòô bàř fòô bàř')->replaceBeginning('fòô', ''); // ' bàř bàř'
Replaces all occurrences of $search in $str by $replacement.
s('fòô bàř fòô bàř')->replaceEnding('bàř', ''); // 'fòô bàř fòô '
Returns a reversed string. A multibyte version of strrev().
s('fòôbàř')->reverse(); // 'řàbôòf'
Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
s('What are your plans today?')->safeTruncate(22, '...'); // 'What are your plans...'
A multibyte str_shuffle() function. It returns a string with its characters in random order.
s('fòôbàř')->shuffle(); // 'àôřbòf'
Converts the string into an URL slug. This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $replacement. The replacement defaults to a single dash, and the string is also converted to lowercase.
s('Using strings like fòô bàř')->slugify(); // 'using-strings-like-foo-bar'
Remove css media-queries.
s('test @media (min-width:660px){ .des-cla #mv-tiles{width:480px} } test ')->stripeCssMediaQueries(); // 'test test '
Remove empty html-tag. e.g.:
s('foo<h1></h1>bar')->stripeEmptyHtmlTags(); // 'foobar'
Strip all whitespace characters. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.
s(' Ο συγγραφέας ')->stripWhitespace(); // 'Οσυγγραφέας'
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.
s('FÒÔbàřbaz')->startsWith('fòôbàř', false); // true
Returns true if the string begins with any of $substrings, false otherwise. By default the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.
s('FÒÔbàřbaz')->startsWith(['fòô', 'bàř'], false); // true
Returns the substring beginning at $start, and up to, but not including the index specified by $end. If $end is omitted, the function extracts the remaining string. If $end is negative, it is computed from the end of the string.
s('fòôbàř')->slice(3, -1); // 'bà'
Returns a lowercase string with underscore, the convention traditionally had no specific name: the Python style guide refers to it simply as "lower_case_with_underscores". The name "snake_case" comes from the Ruby community.
s('foo1 Bar')->snakeize(); // 'foo_1_bar'
Splits the string with the provided regular expression, returning an array of Stringy objects. An optional integer $limit will truncate the results.
s('foo,bar,baz')->split(',', 2); // ['foo', 'bar']
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.
s('fòôbàř')->substr(2, 3); // 'ôbà'
Surrounds a string with the given substring.
s(' ͜ ')->surround('ʘ'); // 'ʘ ͜ ʘ'
Returns a case swapped version of the string.
s('Ντανιλ')->swapCase(); // 'νΤΑΝΙΛ'
Returns a string with smart quotes, ellipsis characters, and dashes from Windows-1252 (commonly used in Word documents) replaced by their ASCII equivalents.
s('“I see…”')->tidy(); // '"I see..."'
Returns a trimmed string with the first letter of each word capitalized. Also accepts an array, $ignore, allowing you to list words not to be capitalized.
$ignore = ['at', 'by', 'for', 'in', 'of', 'on', 'out', 'to', 'the'];
s('i like to watch television')->titleize($ignore); // 'I Like to Watch Television'
Returns an ASCII version of the string. A set of non-ASCII characters are replaced with their closest ASCII counterparts, and the rest are removed unless instructed otherwise.
s('fòôbàř')->toAscii(); // 'foobar'
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. For other numeric strings, their sign will determine the return value. In addition, blank strings consisting of only whitespace will return false. For all other strings, the return value is a result of a boolean cast.
s('OFF')->toBoolean(); // false
Return Stringy object as string, but you can also use (string) for automatically casting the object into a string.
s('fòôbàř')->toString(); // 'fòôbàř'
Converts all characters in the string to lowercase.
s('FÒÔBÀŘ')->toLowerCase(); // 'fòôbàř'
Converts each tab in the string to some number of spaces, as defined by $tabLength. By default, each tab is converted to 4 consecutive spaces.
s(' String speech = "Hi"')->toSpaces(); // ' String speech = "Hi"'
Converts each occurrence of some consecutive number of spaces, as defined by $tabLength, to a tab. By default, each 4 consecutive spaces are converted to a tab.
s(' fòô bàř')->toTabs(); // ' fòô bàř'
Converts the first character of each word in the string to uppercase.
s('fòô bàř')->toTitleCase(); // 'Fòô Bàř'
Converts all characters in the string to uppercase.
s('fòôbàř')->toUpperCase(); // 'FÒÔBÀŘ'
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.
s(' fòôbàř ')->trim(); // 'fòôbàř'
Returns a string with whitespace removed from the start of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
s(' fòôbàř ')->trimLeft(); // 'fòôbàř '
Returns a string with whitespace removed from the end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
s(' fòôbàř ')->trimRight(); // ' fòôbàř'
Truncates the string to a given length. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding the desired length.
s('What are your plans today?')->truncate(19, '...'); // 'What are your pl...'
Returns a lowercase and trimmed string separated by underscores. Underscores are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces as well as dashes.
s('TestUCase')->underscored(); // 'test_u_case'
Returns an UpperCamelCase version of the supplied string. It trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, underscores.
s('Upper Camel-Case')->upperCamelize(); // 'UpperCamelCase'
Converts the first character of the supplied string to upper case.
s('σ foo')->upperCaseFirst(); // 'Σ foo'
urlify(string $separator = '-', string $language = 'en', array $replacements = [], bool $strToLower = true) : static
Converts the string into an URL slug. This includes replacing non-ASCII characters with their closest ASCII equivalents, removing remaining non-ASCII and non-alphanumeric characters, and replacing whitespace with $separator. The separator defaults to a single dash, and the string is also converted to lowercase.
s('Using strings like fòô bàř - 1$')->urlify(); // 'using-strings-like-foo-bar-1-dollar'
Converts the string into an valid UTF-8 string.
s('Düsseldorf')->utf8ify(); // 'Düsseldorf'
From the project directory, tests can be ran using phpunit
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
- Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
- Thanks to StyleCI for the simple but powerfull code style check.
- Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!
Released under the MIT License - see LICENSE.txt
for details.