Set of utility functions for strings in PHP.
Started in 2011 by Martin Jansen, primarily for personal entertainment.
Extended in 2016 by Kay Stenschke.
Most of that stuff isn’t tested that well (though there are unit tests available)
and the API and the behaviour of the functions is likely to change. You have been warned.
Returns true if the string haystack contains the substring needle. Returns false otherwise.
If the optional third parameter is set to true, the test is performed in a case-insensitive manner.
Returns true if the string haystack ends with the substring needle. Returns false otherwise.
If the optional third parameter is set to true, the test is performed in a case-insensitive manner.
Splits the given string by the given delimiter (or default: “,”) into integers.
Returns true if all cased characters in the given input string are lowercase and if the string contains at least one cased character. Returns false otherwise.
Returns true if all cased characters in the given input string are uppercase and if the string contains at least one cased character. Returns false otherwise.
Returns true if the given string is empty or contains whitespace characters only. Returns false otherwise.
Generates a (mostly) speakable random string of given length and options.
Returns true if the given string starts with a number, or optionally a negative number. Returns false otherwise.
Returns true if the string haystack starts with the substring needle. Returns false otherwise.
If the optional third parameter is set to true, the test is performed in a case-insensitive manner.
Returns the given string with uppercase characters converted to their lowercase representations and vice versa.
Unwraps the given string (removes given left- and right-hand-side strings, if found)
Returns the given string wrapped with given left-hand-side and right-hand-side strings.
Optionally checks whether the given string already starts and ends with the given left- and right-hand-side wraps, returns the unaltered input string than.
All the stuff in here is licensed under the New BSD License. See the
included LICENSE file for more info. Have fun!
$ phpize
$ ./configure
$ make -B
Should you run into issues regarding PHP’s buildconf script at some point,
try forcing autoconf and autoheader to version 2.13. (Make sure those are
installed, of course.)
$ PHP_AUTOHEADER=autoheader213 PHP_AUTOCONF=autoconf213 ./buildconf
Not sure why those things still have to be so complicated in the 21st
century.
$ export TEST_PHP_EXECUTABLE=./sapi/cli/php
$ php run-tests.php ./ext/str/tests/
- add options to str_intexplode – unique, positive
- str_reducecharrepetitions(string, char, max_repetitions) : string
- str_removenonnumericchars($str, $convertToInt = false) – Reduce given string to its contained numbers
- str_filter($str, $allowedChars) – Remove all characters not contained in $allowedChars from $str
- str_formatamountdigits($str, $digits) – format numeric string to given amount of digits
- str_camelize($string, $delimiter = ’ ’, $upperCaseFirstLetter = false)
- str_cameltowords($string, $glue = ’ ’, $upperCaseFirstLetter = true)
- str_endsnumerical(haystack [, allow_negative = false]) : bool
- str_between(string, lhs, rhs, offsetLhs = 0, offsetRhs = 0) – get substring after/before/inbetween lhs/rhs
- str_htmltoplaintext($str) – remove all html tags
- str_replaceBetween($str, $needle1, $needle2, $replacement)
- arr_strtolower – perform strtolower() on all items of given array