marjovanlier / stringmanipulation
A PHP library for efficient string manipulation, focusing on data normalisation, encoding conversion and validation.
Requires
- php: >=8.3.0|>=8.4.0
Requires (Dev)
- enlightn/security-checker: >=2.0
- infection/infection: >=0.29.14
- laravel/pint: >=1.22.1
- phan/phan: >=5.4.5
- php-parallel-lint/php-parallel-lint: >=1.4.0
- phpmd/phpmd: >=2.15
- phpstan/extension-installer: >=1.4.3
- phpstan/phpstan: >=2.1.17
- phpstan/phpstan-strict-rules: >=2.0.4
- phpunit/phpunit: >=11.0.9|>=12.0.2
- psalm/plugin-phpunit: >=0.19.3
- rector/rector: >=2.0.16
- roave/security-advisories: dev-latest
- vimeo/psalm: >=6.7
- dev-main
- 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-add-claude-github-actions-1748029083867
- dev-fix/documentation-and-spelling-updates
- dev-add-claude-github-actions-1747991693286
- dev-add-claude-github-actions-1747991693306
This package is auto-updated.
Last update: 2025-05-23 20:13:42 UTC
README
Table of Contents
Introduction
Welcome to the StringManipulation
library, a robust and efficient PHP toolkit designed to enhance string handling in
your PHP projects. With its user-friendly interface and performance-oriented design, this library is an essential
addition for developers looking to perform complex string manipulations with ease.
Features
- Search Words: Transform strings into a search-optimised format for database queries, removing unnecessary characters and optimising for search engine algorithms.
- Name Fix: Standardise last names by capitalising the first letter of each part of the name and handling prefixes correctly, ensuring consistency across your data.
- UTF-8 to ANSI: Convert UTF-8 encoded characters to their ANSI equivalents, facilitating compatibility with systems that do not support UTF-8.
- Remove Accents: Strip accents and special characters from strings to normalise text, making it easier to search and compare.
- Date Validation: Ensure date strings conform to specified formats and check for logical consistency, such as correct days in a month.
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
To ensure the reliability and functionality of your string manipulations, it's recommended to run the entire test suite with the following command:
./vendor/bin/phpunit
To run specific tests or test suites, you can use PHPUnit flags to filter tests. For example, to run tests in a specific file:
./vendor/bin/phpunit --filter testFileName
And to run tests matching a specific name pattern:
./vendor/bin/phpunit --filter '/::testNamePattern$/'
System Requirements
- PHP 8.3 or later.
Support
For support, please open an issue on our GitHub repository.