Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

hedii/helpers

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

About

A collection of php helper functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages