PHP code example of romanlazko / str

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

    

romanlazko / str example snippets


use RomanLazko\Str\Str;

// Get string length
$length = Str::length('Hello World'); // 11

// Convert to kebab-case
$kebab = Str::kebab('fooBar'); // 'foo-bar'

// Convert to snake_case
$snake = Str::snake('fooBar'); // 'foo_bar'
// Convert to camelCase
$camel = Str::camel('foo-bar'); // 'fooBar'
// Convert to StudlyCase
$studly = Str::studly('foo_bar'); // 'FooBar'

// String manipulation
$reversed = Str::reverse('Hello'); // 'olleH'
$limited = Str::limit('This is a long string', 10); // 'This is a...'
$words = Str::words('This is a long string', 3); // 'This is a...'

// Chainable string manipulation
$result = str('Hello World')
    ->upper()
    ->replace('WORLD', 'Universe')
    ->finish('!')
    ->toString();
// Result: 'HELLO UNIVERSE!'

  $result = str('hello')->upper()->finish('!'); // 'HELLO!'