jemer / string-helper
String and path utility classes
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/jemer/string-helper
Requires (Dev)
- phpunit/phpunit: ^11.5
README
A lightweight PHP library providing useful string, path, and table helper functions.
Features
- String manipulation utilities
- Path handling helpers
- Table utility
- Easy to integrate and extend
- Fully tested with PHPUnit
Installation
Install via Composer:
composer require jemer/string-helper
PathHelper utility
use Jemer\StringHelper\PathHelper; // Get the filename from a path echo PathHelper::fileName("/var/www/index.php"); // index.php // Get the filename without extension echo PathHelper::fileNameWithoutExtension("/var/www/index.php"); // index // Get the extension from a file path echo PathHelper::extension("/var/www/index.php"); // php // Get all files from a directory (non-recursive) print_r(PathHelper::getFiles("/path/to/directory")); // Get all subdirectories from a directory print_r(PathHelper::getDirectories("/path/to/directory")); // Generate a path by joining parts echo PathHelper::generatePath(["var", "www", "html"]); // var/www/html (or platform-specific separators) // Get the containing directory for a file echo PathHelper::containingDirectory("/var/www/index.php"); // /var/www
String Builder utility
use Jemer\StringHelper\StringBuilder; // Create a new StringBuilder instance $stringBuilder = new StringBuilder(); // Add a simple string $stringBuilder->Add("Hello, world!"); // Add an indented line (2 tabs) $stringBuilder->Add_Indented("This is indented text.", 2); // Add a comment line $stringBuilder->AddComment("This is a comment"); // Add a horizontal dashed line of width 10 $stringBuilder->AddHorizontalLine(10); // Add text surrounded by new lines $stringBuilder->AddNewLineText("This text has blank lines before and after"); // Add just a new line $stringBuilder->AddNewLine(); // Convert the built lines to a single string and output echo $stringBuilder->ToString(); /* Output example: Hello, world! This is indented text. //This is a comment ---------- This text has blank lines before and after */ // Clear the builder content to start fresh $stringBuilder->Clear();
Table utility
use Jemer\StringHelper\Table; $table = new Table(); $table->setHeaders(['ID', 'Name', 'Email']); $table->addRow(['1', 'John Doe', 'john@example.com']); $table->addRow(['2', 'Jane Smith', 'jane@example.com']); echo $table->render(); //outputs: +----+------------+----------------------+ | ID | Name | Email | +----+------------+----------------------+ | 1 | John Doe | john@example.com | | 2 | Jane Smith | jane@example.com | +----+------------+----------------------+
Running Tests
vendor/bin/phpunit
Contributing
Contributions are welcome! Please fork the repo and submit a pull request.