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.
- Search Words: Transform strings into a search-optimized format for database queries, removing unnecessary characters and optimizing for search engine algorithms.
- Name Fix: Standardize last names by capitalizing 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 normalize 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.
- Time Part Validation: Validate the time components within date strings for accuracy, ensuring that hours, minutes, and seconds are within valid ranges.
Install the package via Composer with the following command:
composer require marjovanlier/stringmanipulation
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'
This library is licensed under the MIT License. For more information, please refer to the License File.
- 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'
use MarjovanLier\StringManipulation\StringManipulation;
$ansiString = StringManipulation::utf8Ansi('Äpfel');
echo $ansiString; // Outputs: 'Äpfel' in ANSI format
This feature optimizes strings for database queries by removing unnecessary characters and optimizing for search engine algorithms.
use MarjovanLier\StringManipulation\StringManipulation;
$result = StringManipulation::searchWords('Hello_World');
echo $result; // Outputs: 'hello world'
Standardize last names by capitalizing 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'
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' in ANSI format
Strip accents and special characters from strings to normalize text, making it easier to search and compare.
use MarjovanLier\StringManipulation\StringManipulation;
$normalizedString = StringManipulation::removeAccents('Crème Brûlée');
echo $normalizedString; // Outputs: 'Creme Brulee'
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::validateDate('2023-02-29');
echo $isValidDate ? 'Valid' : 'Invalid'; // Outputs: 'Invalid'
Validate the time components within date strings for accuracy, ensuring that hours, minutes, and seconds are within valid ranges.
use MarjovanLier\StringManipulation\StringManipulation;
$isValidTime = StringManipulation::validateTime('25:61:00');
echo $isValidTime ? 'Valid' : 'Invalid'; // Outputs: 'Invalid'
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.
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!
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$/'
- PHP 8.2 or later.
For support, please open an issue on our GitHub repository.