2017 © Pedro Peláez
 

library php-component-stringutility

image

jonasrudolph/php-component-stringutility

  • Thursday, August 10, 2017
  • by jonasrudolph
  • Repository
  • 1 Watchers
  • 2 Stars
  • 679 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 16 % Grown

The README.md

Build Status Dependency Status
BCH compliance Codacy Badge, (*1)

php-component-stringutility

  • Well tested functions on strings:
use JonasRudolph\PHPComponents\StringUtility\Base\StringUtilityInterface;
use JonasRudolph\PHPComponents\StringUtility\Implementation\StringUtility;

/** @var StringUtilityInterface */
$stringUtility = new StringUtility();

$stringUtility->contains('mySecr3t', 'cr3') === true

$stringUtility->startsWith('https://my-domain.com', 'https') === true

$stringUtility->endsWith('www.my-domain.com/img/logo.svg', '.svg') === true;

$stringUtility->removePrefix('http://www.my-domain.com', 'http://') === 'www.my-domain.com'

$stringUtility->removeSuffix('my-domain.com', '.com') === 'my-domain'

$stringUtility->removeWhitespace("Any String\tWith\nWhitespace\r.\0") === 'AnyStringWithWitespace.'

$stringUtility->substringAfter('www.my-domain.com/index.php', '.com/') === 'index.php'

$stringUtility->substringBefore('www.my-domain.com/user?id=1&token=xyz', '?') === 'www.my-domain.com/user'

$stringUtility->substringBetween('there is no foo without a bar', 'no ', ' without') === 'foo'

$stringUtility->split('user@my-domain.com:secret', ':') === ['user@my-domain.com', 'secret']

Consistent rules used in all functions

  • When a function searches for a needle anywhere in a string and the string contains the needle more than once - then, the function will use the first occurence of the needle in the string for further computations
    That means:, (*2)

    $stringUtility->substringAfter('abefbg', 'b') === 'efbg'
    $stringUtility->substringBefore('abefbg', 'b') === 'a'
    $stringUtility->split('user@my-domain.com:secret', ':') === ['user@my-domain.com', 'secret']
    

    One exception is the substringBetween function which will search for the first $untilBefore-string after the occurence of the first $startAfter-string, (*3)

    $stringUtility->substringBetween('abefbg', 'b', 'b') === 'ef'
    $stringUtility->substringBetween('abefbg', 'e', 'b') === 'f'
    $stringUtility->substringBetween('abcdefg', 'c', 'b') === 'defg'
    
  • Every character of a a string is surrounded by the empty string ('') infinitly times
    That means:, (*4)

    $stringUtility->contains($myString, '') === true
    $stringUtility->startsWith($myString, '') === true
    $stringUtility->endsWith($myString, '') === true;
    $stringUtility->substringAfter($myString, '') === $myString
    $stringUtility->substringBefore($myString, '') === ''
    $stringUtility->substringBetween('abcd', '', 'b') === 'a'
    $stringUtility->substringBetween($myString, $x, '') === ''
    $stringUtility->split($myString, '') === ['', $myString]
    

Contributors

The Versions

10/08 2017

dev-master

9999999-dev

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

utility string split contains startswith endswith removeprefix removesuffix removewhitespace substringafter substringbefore substringbetween

02/03 2017

1.2.1

1.2.1.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

utility string split contains startswith endswith removeprefix removesuffix removewhitespace substringafter substringbefore substringbetween

04/02 2017

1.2.0

1.2.0.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

utility string split contains startswith endswith removeprefix removesuffix removewhitespace substringafter substringbefore substringbetween

01/07 2016

1.1.2

1.1.2.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

01/07 2016

1.1.1

1.1.1.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

03/06 2016

1.1.0

1.1.0.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph

05/05 2016

1.0.0

1.0.0.0

  Sources   Download

LGPLv3

The Requires

  • php >=5.5

 

The Development Requires

by Jonas Rudolph