Giter Club home page Giter Club logo

helpers's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.