composer install weew/helpers-string
This tiny library provides various helper functions to deal with common string manipulation related problems.
Simple helper to format strings. Supports placeholders like :key
and %s
.
string s(string $format, mixed $args [, mixed $...])
Check if a string starts with the given sequence.
bool str_starts_with(string $string, string $search [, bool $caseSensitive = false])
heck if a string ends with the given sequence.
bool str_ends_with(string $string, string $search [, bool $caseSensitive = false])
Combine multiple strings to a url. This function makes sure the pieces are properly glued together with a /
and eliminates all //
, except after the protocol.
string url(string $paths [, $...])
Combine multiple strings to a path. Glues pieces together with the proper directory separator and eliminates all //
or \\
.
string path(string $paths [, $...])
Get type of a value. Returns values like int
, string
, function
. Objects will return its class name.
string get_type(mixed $abstract)
Convert string to snake_case.
string str_snake_case(string $string)
Convert string to StudlyCase.
string str_studly_caps(string $string [, array $delimiters = ['-', '_']])
Convert a string to camelCase.
string str_camel_case(string $string [, array $delimiters = ['-', '_']])
Generate a random alphanumeric string. Works only with even numbers.
string str_random([int $length = 10])
Split a string by one or multiple delimiters. Works the same way as the explode
function, but allows several delimiters.
string str_explode(string $string, string|array $delimiter [, int $limit = PHP_INT_MAX])
Generate a v4 uuid.
string uuid([string $prefix = null, int $length = 36])
Format string as a v4 uuid.
string uuid_format(string $string [, string $prefix = null, int $length = null])
Generate a uuid of a simpler format.
string simple_uuid()
Format an xml string.
string format_xml($string)