PHP code example of jonasrudolph / php-component-stringutility

1. Go to this page and download the library: Download jonasrudolph/php-component-stringutility library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jonasrudolph / php-component-stringutility example snippets

 
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('[email protected]:secret', ':') === ['[email protected]', 'secret']
  
    $stringUtility->substringAfter('abefbg', 'b') === 'efbg'
    $stringUtility->substringBefore('abefbg', 'b') === 'a'
    $stringUtility->split('[email protected]:secret', ':') === ['[email protected]', 'secret']
    
  
    $stringUtility->substringBetween('abefbg', 'b', 'b') === 'ef'
    $stringUtility->substringBetween('abefbg', 'e', 'b') === 'f'
    $stringUtility->substringBetween('abcdefg', 'c', 'b') === 'defg'
    

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