Collection of useful php string helpers.


License
MIT

Documentation

String helpers

Build Status Test Coverage Version Licence

Table of contents

Installation

composer install weew/helpers-string

Introduction

This tiny library provides various helper functions to deal with common string manipulation related problems.

Functions

s

Simple helper to format strings. Supports placeholders like :key and %s.

string s(string $format, mixed $args [, mixed $...])

str_starts_with

Check if a string starts with the given sequence.

bool str_starts_with(string $string, string $search [, bool $caseSensitive = false])

str_ends_with

heck if a string ends with the given sequence.

bool str_ends_with(string $string, string $search [, bool $caseSensitive = false])

url

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 [, $...])

path

Combine multiple strings to a path. Glues pieces together with the proper directory separator and eliminates all // or \\.

string path(string $paths [, $...])

get_type

Get type of a value. Returns values like int, string, function. Objects will return its class name.

string get_type(mixed $abstract)

str_snake_case

Convert string to snake_case.

string str_snake_case(string $string)

str_studly_caps

Convert string to StudlyCase.

string str_studly_caps(string $string [, array $delimiters = ['-', '_']])

str_camel_case

Convert a string to camelCase.

string str_camel_case(string $string [, array $delimiters = ['-', '_']])

str_random

Generate a random alphanumeric string. Works only with even numbers.

string str_random([int $length = 10])

str_explode

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])

uuid

Generate a v4 uuid.

string uuid([string $prefix = null, int $length = 36])

uuid_format

Format string as a v4 uuid.

string uuid_format(string $string [, string $prefix = null, int $length = null])

simple_uuid

Generate a uuid of a simpler format.

string simple_uuid()

format_xml

Format an xml string.

string format_xml($string)