marjovanlier / stringmanipulation
High-performance PHP 8.3+ string manipulation library featuring O(n) algorithms with up to 5x speed improvements. Provides Unicode-aware operations including searchWords(), nameFix(), utf8Ansi(), removeAccents(), and isValidDate() with comprehensive testing infrastructure.
Requires
- php: >=8.3.0|>=8.4.0
Requires (Dev)
- enlightn/security-checker: >=2.0
- infection/infection: >=0.31.2
- laravel/pint: >=1.24.0
- phan/phan: >=5.5.1
- php-parallel-lint/php-parallel-lint: >=1.4.0
- phpmd/phpmd: >=2.15
- phpstan/extension-installer: >=1.4.3
- phpstan/phpstan: >=2.1.22
- phpstan/phpstan-strict-rules: >=2.0.6
- phpunit/phpunit: >=11.0.9|>=12.0.2
- psalm/plugin-phpunit: >=0.19.3
- rector/rector: >=2.1.4
- roave/security-advisories: dev-latest
- vimeo/psalm: >=6.7
- dev-main
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v1.0.85
- v1.0.84
- v1.0.83
- v1.0.82
- v1.0.81
- v1.0.80
- v1.0.79
- v1.0.78
- v1.0.77
- v1.0.76
- v1.0.75
- v1.0.74
- v1.0.73
- v1.0.72
- v1.0.71
- v1.0.70
- v1.0.69
- v1.0.68
- v1.0.67
- v1.0.66
- v1.0.65
- v1.0.64
- v1.0.63
- v1.0.62
- v1.0.61
- v1.0.60
- v1.0.59
- v1.0.58
- v1.0.57
- v1.0.56
- v1.0.55
- v1.0.54
- v1.0.53
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-feature/gitignore-whitelist
- dev-feature/performance-optimization-o-n
- dev-comprehensive-name-tests
- dev-add-claude-github-actions-1755862980984
This package is auto-updated.
Last update: 2025-08-23 07:43:41 UTC
README
Table of Contents
- Introduction
- Features
- Performance Benchmarks
- Installation
- Usage
- Advanced Usage
- Testing & Quality Assurance
- System Requirements
- Contributing
- Support
Introduction
Welcome to the StringManipulation
library, a high-performance PHP 8.3+ toolkit designed for complex and efficient
string handling. Following a recent suite of O(n) optimisations, the library is now 2-5x faster, making it one of
the most powerful and reliable solutions for developers who require speed and precision in their PHP applications.
This library specialises in Unicode handling, data normalisation, encoding conversion, and validation with comprehensive testing and quality assurance.
Features
removeAccents()
: Efficiently strips accents and diacritics to normalise text. Powered by O(n) optimisations using hash table lookups, this high-performance feature makes text comparison and searching faster than ever (981,436+ ops/sec).searchWords()
: Transforms strings into a search-optimised format ideal for database queries. This high-performance function intelligently removes irrelevant characters and applies single-pass algorithms to improve search accuracy (387,231+ ops/sec).nameFix()
: Standardises names by capitalising letters and correctly handling complex prefixes. Its performance-oriented design with consolidated regex operations ensures consistent data formatting at scale (246,197+ ops/sec).utf8Ansi()
: Convert UTF-8 encoded characters to their ANSI equivalents with comprehensive Unicode mappings, facilitating compatibility with legacy systems.isValidDate()
: Comprehensive date validation utility that ensures date strings conform to specified formats and validates logical consistency.- Comprehensive Unicode/UTF-8 Support: Built from the ground up to handle a wide range of international characters with optimised character mappings, ensuring your application is ready for a global audience.
Performance Benchmarks
The library has undergone extensive performance tuning, resulting in 2-5x speed improvements through O(n) optimisation algorithms. Our benchmarks demonstrate the library's capability to handle high-volume data processing efficiently:
Method | Performance | Optimisation Technique |
---|---|---|
removeAccents() |
981,436+ ops/sec | Hash table lookups with strtr() |
searchWords() |
387,231+ ops/sec | Single-pass combined mapping |
nameFix() |
246,197+ ops/sec | Consolidated regex operations |
Benchmarks measured on standard development environments. Actual performance may vary based on hardware, string length, and complexity.
Key Optimisation Features:
- O(n) complexity algorithms for all core methods
- Static caching for character mapping tables
- Single-pass string transformations
- Minimal memory allocation in critical paths
Installation
Install the package via Composer with the following command:
composer require marjovanlier/stringmanipulation
Usage
For more detailed examples of each feature, please refer to the corresponding sections below.
use MarjovanLier\StringManipulation\StringManipulation; $result = StringManipulation::searchWords('Hello_World'); echo $result; // Outputs: 'hello world'
License
This library is licensed under the MIT License. For more information, please refer to the License File.
Detailed Examples
Name Standardisation
- Case Conversion: Easily convert strings between upper case, lower case, and title case, allowing for flexible text formatting and presentation. For example, converting 'john doe' to 'John Doe' for proper name presentation.
use MarjovanLier\StringManipulation\StringManipulation; $fixedName = StringManipulation::nameFix('mcdonald'); echo $fixedName; // Outputs: 'McDonald'
Search Words
This feature optimises strings for database queries by removing unnecessary characters and optimising for search engine algorithms.
use MarjovanLier\StringManipulation\StringManipulation; $result = StringManipulation::searchWords('Hello_World'); echo $result; // Outputs: 'hello world'
Name Fix
Standardise last names by capitalising the first letter of each part of the name and handling prefixes correctly.
use MarjovanLier\StringManipulation\StringManipulation; $fixedName = StringManipulation::nameFix('de souza'); echo $fixedName; // Outputs: 'De Souza'
UTF-8 to ANSI Conversion
Convert UTF-8 encoded characters to their ANSI equivalents, facilitating compatibility with systems that do not support UTF-8.
use MarjovanLier\StringManipulation\StringManipulation; $ansiString = StringManipulation::utf8Ansi('Über'); echo $ansiString; // Outputs: 'Uber'
Remove Accents
Strip accents and special characters from strings to normalise text, making it easier to search and compare.
use MarjovanLier\StringManipulation\StringManipulation; $normalisedString = StringManipulation::removeAccents('Crème Brûlée'); echo $normalisedString; // Outputs: 'Creme Brulee'
Date Validation
Ensure date strings conform to specified formats and check for logical consistency, such as correct days in a month.
use MarjovanLier\StringManipulation\StringManipulation; $isValidDate = StringManipulation::isValidDate('2023-02-29', 'Y-m-d'); echo $isValidDate ? 'Valid' : 'Invalid'; // Outputs: 'Invalid'
Advanced Usage
For more complex string manipulations, consider chaining functions to achieve unique transformations. For instance, you could first normalise a string, apply a search optimisation, and finally standardise the casing for a comprehensive text processing example.
use MarjovanLier\StringManipulation\StringManipulation; $originalString = 'Crème Brûlée'; $processedString = StringManipulation::nameFix(StringManipulation::utf8Ansi(StringManipulation::removeAccents($originalString))); echo $processedString; // Outputs: 'Creme Brulee'
This approach allows for flexible and powerful string manipulations by combining the library's functions to suit your specific needs.
Contributing
We welcome contributions to the StringManipulation
library! If you're interested in helping, please follow these
steps:
- Fork the repository and create your feature branch.
- Ensure your changes adhere to our coding standards and include tests if applicable.
- Submit a pull request with a detailed description of your changes.
Thank you for your interest in improving our library!
Testing & Quality Assurance
We are committed to delivering reliable, high-quality code. Our library is rigorously tested using a comprehensive suite of tools to ensure stability and correctness.
Docker-Based Testing (Recommended)
For a consistent and reliable testing environment, we recommend using Docker. Our Docker setup includes PHP 8.3 with all required extensions:
# Run complete test suite docker-compose run --rm test-all # Run individual test suites docker-compose run --rm test-phpunit # PHPUnit tests docker-compose run --rm test-phpstan # Static analysis docker-compose run --rm test-code-style # Code style docker-compose run --rm test-infection # Mutation testing
Local Testing
If you have a local PHP 8.3+ environment configured:
# Complete test suite composer tests # Individual tests ./vendor/bin/phpunit --filter testClassName ./vendor/bin/phpunit --filter '/::testMethodName$/'
Our Quality Suite Includes:
- PHPUnit: 166 comprehensive tests with 100% code coverage ensuring functional correctness
- Mutation Testing: 88% Mutation Score Indicator (MSI) with Infection, guaranteeing our tests are robust and meaningful
- Static Analysis: Proactive bug detection using:
- PHPStan (level max, strict rules)
- Psalm (level 1, 99.95% type coverage)
- Phan (clean analysis results)
- PHPMD (mess detection)
- Code Style: Automated formatting with Laravel Pint (PSR compliance)
- Performance Benchmarks: Continuous performance monitoring with comprehensive benchmarking suite
System Requirements
- PHP 8.3 or later (strict typing enabled)
mbstring
extension for multi-byte string operationsintl
extension for internationalisation and advanced Unicode support- Enabled
declare(strict_types=1);
for robust type safety - Composer for package management
Support
For support, please open an issue on our GitHub repository.