PHP code example of lukaswhite / string-utilities

1. Go to this page and download the library: Download lukaswhite/string-utilities 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/ */

    

lukaswhite / string-utilities example snippets


Strings::stripPunctuation( 
	'This, is a sentence, with - some - punctuation.' 
);
// outputs This is a sentence with  some  punctuation

Strings::stripMultipleSpaces(
	'This is  a string that has  some extra spaces'
);
// outputs This is a string that has some extra spaces

Strings::replaceNth( '0', '1', '0000000000', 5 );
// Outputs 0000100000

Strings::replaceAllButFirstOccurence( '0', '1', '0000000000' );
// Outputs 0111111111

Strings::randomHex( 5 );
// Outputs something like de0f42

Strings::randomHex( 5, true );
// Outputs something like DE0F42

Strings::startsWith( 'This is a test', 'This' )
// true

Strings::startsWith( 'This is a test', 'this', false )
// true

Strings::startsWith( 'This is a test', 'test' )
// true

Strings::startsWith( 'This is a test', 'Test', false )
// true

$excerpt = Strings::excerpt( $content, 25 );

$excerpt = Strings::excerpt( 
	$content, 
	100,
	'<a href="/path/to/page">Read More</a>'
);

$excerpt = Strings::excerptCharacters( $content, 200 );