A collection of php helper functions
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src Update helpers.php Oct 4, 2016
tests Add is_url function Sep 15, 2016
.gitignore
.travis.yml Initial Sep 14, 2016
LICENSE.md Initial Sep 14, 2016
composer.json Initial Sep 14, 2016
phpunit.xml Initial Sep 14, 2016
readme.md Update readme.md Apr 27, 2017

readme.md

Build Status

Helpers

A collection of php helper functions

Table of contents

Installation

Install via composer

composer require hedii/helpers

Usage

Available functions

Functions description

string_without(string $haystack, string $needle)

Remove a substring from a string. It returns the original string if the substring is not found.

$string = string_without('This is my name', ' is ');

// Thismy name

$string = string_without('This is my name', 'some string');

// This is my name

string_before(string $haystack, string $needle)

Get the string before a delimiter. It returns false if the string does not contains the delimiter.

$string = string_before('This is my name', ' name');

// This is my

$string = string_before('This is my name', 'some string');

// false

string_after(string $haystack, string $needle)

Get the string after a delimiter. It returns false if the string does not contains the delimiter.

$string = string_after('This is my name', 'This ');

// is my name

$string = string_after('This is my name', 'some string');

// false

string_between(string $haystack, string $needle1, string $needle2)

Get the string between two delimiters. It returns false if the string does not contains the two delimiters.

$string = string_between('This is my name', 'This ', ' name');

// is my

$string = string_between('This is my name', 'some', ' string');

// false

string_starts_with(string $haystack, string|array $needles)

Determines if the given string begins with the given value.

$value = string_starts_with('This is my name', 'This');

// true

string_ends_with(string $haystack, string|array $needles)

Determines if the given string ends with the given value.

$value = string_ends_with('This is my name', 'name');

// true

string_length(string $string)

Get the length of the given string.

$length = string_length('abcd');

// 4

string_is(string $pattern, string $string)

Determines if a given string matches a given pattern. Asterisks may be used to indicate wildcards.

$value = string_is('foo*', 'foobar');

// true

$value = string_is('baz*', 'foobar');

// false

string_contains(string $haystack, string|array $needles)

Determines if the given string contains the given value.

$value = string_contains('This is my name', 'my');

// true

$value = string_contains('This is my name', ['some string', 'my']);

// true

string_finish(string $string, string $cap)

Adds a single instance of the given value to a string.

$string = string_finish('this/string', '/');

// this/string/

$string = string_finish('this/string/', '/');

// this/string/

string_random(int $length = 32)

Generates a random string of the specified length.

$string = string_random(40);

// 6a2531aabec1fda11b0e0d9eaeb17d7ebfe1cdc5

is_url(string $string)

Determine if a string is a valid url.

is_url('http://example.com');

// true

is_url('tel:+1-111-222-333');

// false

class_basename(string|object $class)

Get the class "basename" of the given object / class.

$basename = class_basename(\Hedii\Helpers\HelpersTest);

// HelpersTest

is_windows_os()

Determine whether the current environment is Windows based.

is_window_os();

// false

Testing

composer test

License

helpers is released under the MIT Licence. See the bundled LICENSE file for details.

helpers contains some content from Laravel illuminate/support package. See the LARAVEL LICENSE file for details.