PHP code example of seworqs / commons-string

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

    

seworqs / commons-string example snippets


use Seworqs\Commons\String\Helper\CaseHelper;
use Seworqs\Commons\String\Helper\RandomHelper;
use Seworqs\Commons\String\Helper\PathHelper;
use Seworqs\Commons\String\Helper\NamespaceHelper;

// CaseHelper: Convert strings to different casing styles
$camel  = CaseHelper::from('This is some text')->toCamelCase()->toString();    // thisIsSomeText
$pascal = CaseHelper::from('This is some text')->toPascalCase()->toString();   // ThisIsSomeText

// RandomHelper: Generate random strings
$default = RandomHelper::createRandomString();                                  // 10 chars
$custom  = RandomHelper::createRandomString(12, 'abdef1234567890');             // Safe character set

// PathHelper: Build path-like structures
$path = PathHelper::fromString('src/utilities/logger');
echo $path->toKebabPath(); // src/utilities/logger

// NamespaceHelper: Format segments as a PHP namespace
$ns = NamespaceHelper::fromString('domain/shared/logger_service');
echo $ns->toNamespace(); // Domain\Shared\LoggerService